
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>配置 &#8212; Django 3.2.11.dev 文档</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="信号" href="signals.html" />
    <link rel="prev" title="SchemaEditor" href="schema-editor.html" />



 
<script src="../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../index.html">Django 3.2.11.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../index.html">Home</a>  |
        <a title="Table of contents" href="../contents.html">Table of contents</a>  |
        <a title="Global index" href="../genindex.html">Index</a>  |
        <a title="Module index" href="../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="schema-editor.html" title="&lt;code class=&#34;docutils literal notranslate&#34;&gt;&lt;span class=&#34;pre&#34;&gt;SchemaEditor&lt;/span&gt;&lt;/code&gt;">previous</a>
     |
    <a href="index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="signals.html" title="信号">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-settings">
            
  <div class="section" id="s-settings">
<span id="settings"></span><h1>配置<a class="headerlink" href="#settings" title="永久链接至标题">¶</a></h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#core-settings" id="id12">核心配置</a></li>
<li><a class="reference internal" href="#auth" id="id13">认证</a></li>
<li><a class="reference internal" href="#messages" id="id14">消息</a></li>
<li><a class="reference internal" href="#sessions" id="id15">会话</a></li>
<li><a class="reference internal" href="#sites" id="id16">站点</a></li>
<li><a class="reference internal" href="#static-files" id="id17">静态文件</a></li>
<li><a class="reference internal" href="#core-settings-topical-index" id="id18">核心配置专题索引</a></li>
</ul>
</div>
<div class="admonition warning">
<p class="first admonition-title">警告</p>
<p class="last">当你覆盖配置时要小心，特别是当默认值是一个非空的列表或字典时，如 <a class="reference internal" href="#std:setting-STATICFILES_FINDERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_FINDERS</span></code></a>。确保你保留了你希望使用的 Django 功能所需要的组件。</p>
</div>
<div class="section" id="s-core-settings">
<span id="core-settings"></span><h2><a class="toc-backref" href="#id12">核心配置</a><a class="headerlink" href="#core-settings" title="永久链接至标题">¶</a></h2>
<p>下面是 Django 核心中可用的配置及其默认值的列表。下面列出了 contrib 应用提供的设置，后面是核心配置的专题索引。关于介绍性资料，请看 <a class="reference internal" href="../topics/settings.html"><span class="doc">配置专题指南</span></a>。</p>
<div class="section" id="s-absolute-url-overrides">
<span id="s-std:setting-ABSOLUTE_URL_OVERRIDES"></span><span id="absolute-url-overrides"></span><span id="std:setting-ABSOLUTE_URL_OVERRIDES"></span><h3><code class="docutils literal notranslate"><span class="pre">ABSOLUTE_URL_OVERRIDES</span></code><a class="headerlink" href="#absolute-url-overrides" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">{}</span></code> （空字典）</p>
<p>将 <code class="docutils literal notranslate"><span class="pre">&quot;app_label.model_name&quot;</span></code> 字符串映射到接受模型对象并返回其 URL 的函数的字典。这是一种在每个预安装基础上插入或覆盖 <code class="docutils literal notranslate"><span class="pre">get_absolute_url()</span></code> 方法的方式。例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ABSOLUTE_URL_OVERRIDES</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">&#39;blogs.weblog&#39;</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">o</span><span class="p">:</span> <span class="s2">&quot;/blogs/</span><span class="si">%s</span><span class="s2">/&quot;</span> <span class="o">%</span> <span class="n">o</span><span class="o">.</span><span class="n">slug</span><span class="p">,</span>
    <span class="s1">&#39;news.story&#39;</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">o</span><span class="p">:</span> <span class="s2">&quot;/stories/</span><span class="si">%s</span><span class="s2">/</span><span class="si">%s</span><span class="s2">/&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">o</span><span class="o">.</span><span class="n">pub_year</span><span class="p">,</span> <span class="n">o</span><span class="o">.</span><span class="n">slug</span><span class="p">),</span>
<span class="p">}</span>
</pre></div>
</div>
<p>在此配置中使用的模型名称应全部为小写，与实际模型类名称的大小写无关。</p>
</div>
<div class="section" id="s-admins">
<span id="s-std:setting-ADMINS"></span><span id="admins"></span><span id="std:setting-ADMINS"></span><h3><code class="docutils literal notranslate"><span class="pre">ADMINS</span></code><a class="headerlink" href="#admins" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>所有收到代码错误通知的人的列表。当 <a class="reference internal" href="#std:setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG=False</span></code></a> 和 <a class="reference internal" href="../topics/logging.html#django.utils.log.AdminEmailHandler" title="django.utils.log.AdminEmailHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">AdminEmailHandler</span></code></a> 中设置了 <a class="reference internal" href="#std:setting-LOGGING"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LOGGING</span></code></a> 时（默认情况下是这样做的），Django 会将请求／响应周期中出现的异常的详细信息通过邮件发送给这些人。</p>
<p>列表中的每个项目应该是一个元组 (全名, 电子邮件地址)。例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[(</span><span class="s1">&#39;John&#39;</span><span class="p">,</span> <span class="s1">&#39;john@example.com&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;Mary&#39;</span><span class="p">,</span> <span class="s1">&#39;mary@example.com&#39;</span><span class="p">)]</span>
</pre></div>
</div>
</div>
<div class="section" id="s-allowed-hosts">
<span id="s-std:setting-ALLOWED_HOSTS"></span><span id="allowed-hosts"></span><span id="std:setting-ALLOWED_HOSTS"></span><h3><code class="docutils literal notranslate"><span class="pre">ALLOWED_HOSTS</span></code><a class="headerlink" href="#allowed-hosts" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>一个代表这个 Django 网站可以服务的主机／域名的字符串列表。这是一个安全措施，以防止 <a class="reference internal" href="../topics/security.html#host-headers-virtual-hosting"><span class="std std-ref">HTTP 主机头攻击</span></a> ，即使在许多看似安全的 Web 服务器配置下也有可能发生。</p>
<p>这个列表中的值可以是完全限定的名称（例如 <code class="docutils literal notranslate"><span class="pre">'www.example.com</span></code>），在这种情况下，它们将与请求的 <code class="docutils literal notranslate"><span class="pre">Host</span></code> 头完全匹配（不区分大小写，不包括端口）。以英文句号开头的值可以用作子域通配符。<code class="docutils literal notranslate"><span class="pre">'.example.com'</span></code> 将匹配 <code class="docutils literal notranslate"><span class="pre">example.com</span></code>、<code class="docutils literal notranslate"><span class="pre">www.example.com</span></code> 和 <code class="docutils literal notranslate"><span class="pre">example.com</span></code> 的任何其他子域。<code class="docutils literal notranslate"><span class="pre">'*'</span></code> 的值将匹配任何东西；在这种情况下，你要负责提供你自己的 <code class="docutils literal notranslate"><span class="pre">Host</span></code> 头的验证（也许是在一个中间件中；如果是这样，这个中间件必须首先在 <a class="reference internal" href="#std:setting-MIDDLEWARE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MIDDLEWARE</span></code></a> 中列出）。</p>
<p>Django 也允许在任何条目中使用 <a class="reference external" href="https://en.wikipedia.org/wiki/Fully_qualified_domain_name">完全合格的域名（FQDN）</a> 。有些浏览器在 <code class="docutils literal notranslate"><span class="pre">Host</span></code> 头中包含了一个尾部的点，Django 在执行主机验证时将其去掉。</p>
<p>如果 <code class="docutils literal notranslate"><span class="pre">Host</span></code> 头（或者 <code class="docutils literal notranslate"><span class="pre">X-Forwarded-Host</span></code> 如果 <a class="reference internal" href="#std:setting-USE_X_FORWARDED_HOST"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_X_FORWARDED_HOST</span></code></a> 被启用的话）不符合这个列表中的任何值，则 <a class="reference internal" href="request-response.html#django.http.HttpRequest.get_host" title="django.http.HttpRequest.get_host"><code class="xref py py-meth docutils literal notranslate"><span class="pre">django.http.HttpRequest.get_host()</span></code></a> 方法将引发 <a class="reference internal" href="exceptions.html#django.core.exceptions.SuspiciousOperation" title="django.core.exceptions.SuspiciousOperation"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SuspiciousOperation</span></code></a>。</p>
<p>当 <code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG`为``True`</span></code> 和 <code class="docutils literal notranslate"><span class="pre">ALLOWED_HOSTS</span></code> 为空时，主机将根据 <code class="docutils literal notranslate"><span class="pre">['.localhost',</span> <span class="pre">'127.0.0.1',</span> <span class="pre">'[::1]']</span></code> 进行验证。</p>
<p><code class="docutils literal notranslate"><span class="pre">ALLOWED_HOSTS</span></code> 也是 <a class="reference internal" href="../topics/testing/advanced.html#topics-testing-advanced-multiple-hosts"><span class="std std-ref">在运行测试时进行检查的</span></a>。</p>
<p>这些验证仅通过 <a class="reference internal" href="request-response.html#django.http.HttpRequest.get_host" title="django.http.HttpRequest.get_host"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_host()</span></code></a> 来实现；如果你的代码直接从 <code class="docutils literal notranslate"><span class="pre">request.META</span></code> 得到 <code class="docutils literal notranslate"><span class="pre">Host</span></code> 头部，你就绕过了这种安全保护机制。</p>
<div class="versionchanged">
<span class="title">Changed in Django 3.1:</span> <p>如果 <code class="docutils literal notranslate"><span class="pre">ALLOWED_HOSTS</span></code> 为空且 <code class="docutils literal notranslate"><span class="pre">DEBUG=True</span></code>，则允许使用 localhost 的子域。</p>
</div>
</div>
<div class="section" id="s-append-slash">
<span id="s-std:setting-APPEND_SLASH"></span><span id="append-slash"></span><span id="std:setting-APPEND_SLASH"></span><h3><code class="docutils literal notranslate"><span class="pre">APPEND_SLASH</span></code><a class="headerlink" href="#append-slash" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">True</span></code></p>
<p>当设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 时，如果请求的 URL 不符合 URLconf 中的任何模式，并且不以斜线结尾，则会发出一个 HTTP 重定向到相同的URL，并附加一个斜线。注意，重定向可能会导致 POST 请求中提交的任何数据丢失。</p>
<p><a class="reference internal" href="#std:setting-APPEND_SLASH"><code class="xref std std-setting docutils literal notranslate"><span class="pre">APPEND_SLASH</span></code></a> 的配置只有在安装了 <a class="reference internal" href="middleware.html#django.middleware.common.CommonMiddleware" title="django.middleware.common.CommonMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">CommonMiddleware</span></code></a> 的情况下才会使用（参见 <a class="reference internal" href="../topics/http/middleware.html"><span class="doc">中间件</span></a>）。也请参见 <a class="reference internal" href="#std:setting-PREPEND_WWW"><code class="xref std std-setting docutils literal notranslate"><span class="pre">PREPEND_WWW</span></code></a>。</p>
</div>
<div class="section" id="s-caches">
<span id="s-std:setting-CACHES"></span><span id="caches"></span><span id="std:setting-CACHES"></span><h3><code class="docutils literal notranslate"><span class="pre">CACHES</span></code><a class="headerlink" href="#caches" title="永久链接至标题">¶</a></h3>
<p>默认：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
    <span class="s1">&#39;default&#39;</span><span class="p">:</span> <span class="p">{</span>
        <span class="s1">&#39;BACKEND&#39;</span><span class="p">:</span> <span class="s1">&#39;django.core.cache.backends.locmem.LocMemCache&#39;</span><span class="p">,</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>一个包含所有 Django 缓存配置的字典。它是一个嵌套的字典，其内容将缓存别名映射到一个包含单个缓存选项的字典中。</p>
<p><a class="reference internal" href="#std:setting-CACHES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CACHES</span></code></a> 配置必须设置一个 <code class="docutils literal notranslate"><span class="pre">default</span></code> 缓存；也可以指定任何数量的附加缓存。如果你使用的是本地内存缓存以外的缓存后端，或者你需要定义多个缓存，则需要其他选项。以下是可用的缓存选项。</p>
<div class="section" id="s-backend">
<span id="s-std:setting-CACHES-BACKEND"></span><span id="backend"></span><span id="std:setting-CACHES-BACKEND"></span><h4><code class="docutils literal notranslate"><span class="pre">BACKEND</span></code><a class="headerlink" href="#backend" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>要使用的缓存后端。内置的缓存后端有：</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">'django.core.cache.backends.db.DatabaseCache'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.core.cache.backends.dummy.DummyCache'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.core.cache.backends.filebased.FileBasedCache'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.core.cache.backends.locmem.LocMemCache'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.core.cache.backends.memcached.PyMemcacheCache'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.core.cache.backends.memcached.PyLibMCCache'</span></code></li>
</ul>
<p>你可以通过将 <a href="#id1"><span class="problematic" id="id2">:set:`BACKEND &lt;CACHES-BACKEND&gt;`</span></a> 设置为一个完全限定的缓存后端类的路径（例如 <code class="docutils literal notranslate"><span class="pre">mypackage.backends.whatever.WhateverCache</span></code>），来使用一个不在 Django 中的缓存后端。</p>
<div class="versionchanged">
<span class="title">Changed in Django 3.2:</span> <p>增加了 <code class="docutils literal notranslate"><span class="pre">PyMemcacheCache</span></code> 后端。</p>
</div>
</div>
<div class="section" id="s-key-function">
<span id="s-std:setting-CACHES-KEY_FUNCTION"></span><span id="key-function"></span><span id="std:setting-CACHES-KEY_FUNCTION"></span><h4><code class="docutils literal notranslate"><span class="pre">KEY_FUNCTION</span></code><a class="headerlink" href="#key-function" title="永久链接至标题">¶</a></h4>
<p>一个字符串，包含一个指向函数（或任何可调用）的点分隔路径，定义如何将前缀、版本和密钥组成一个最终的缓存密钥。默认的实现相当于函数：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">make_key</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">key_prefix</span><span class="p">,</span> <span class="n">version</span><span class="p">):</span>
    <span class="k">return</span> <span class="s1">&#39;:&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">key_prefix</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">version</span><span class="p">),</span> <span class="n">key</span><span class="p">])</span>
</pre></div>
</div>
<p>你可以使用任何你想要的密钥函数，只要它有相同的参数签名。</p>
<p>查看 <a class="reference internal" href="../topics/cache.html#cache-key-transformation"><span class="std std-ref">缓存文档</span></a> 获取更多信息。</p>
</div>
<div class="section" id="s-key-prefix">
<span id="s-std:setting-CACHES-KEY_PREFIX"></span><span id="key-prefix"></span><span id="std:setting-CACHES-KEY_PREFIX"></span><h4><code class="docutils literal notranslate"><span class="pre">KEY_PREFIX</span></code><a class="headerlink" href="#key-prefix" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>一个自动包含在 Django 服务器使用的所有缓存键中的字符串（默认情况下是前缀）。</p>
<p>查看 <a class="reference internal" href="../topics/cache.html#cache-key-prefixing"><span class="std std-ref">缓存文档</span></a> 获取更多信息。</p>
</div>
<div class="section" id="s-location">
<span id="s-std:setting-CACHES-LOCATION"></span><span id="location"></span><span id="std:setting-CACHES-LOCATION"></span><h4><code class="docutils literal notranslate"><span class="pre">LOCATION</span></code><a class="headerlink" href="#location" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>要使用的高速缓存的位置。可能是文件系统缓存的目录，memcache 服务器的主机和端口，或者是本地内存缓存的识别名称，例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">CACHES</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">&#39;default&#39;</span><span class="p">:</span> <span class="p">{</span>
        <span class="s1">&#39;BACKEND&#39;</span><span class="p">:</span> <span class="s1">&#39;django.core.cache.backends.filebased.FileBasedCache&#39;</span><span class="p">,</span>
        <span class="s1">&#39;LOCATION&#39;</span><span class="p">:</span> <span class="s1">&#39;/var/tmp/django_cache&#39;</span><span class="p">,</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="s-options">
<span id="s-std:setting-CACHES-OPTIONS"></span><span id="options"></span><span id="std:setting-CACHES-OPTIONS"></span><h4><code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code><a class="headerlink" href="#options" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>传递给缓存后端的额外参数。可用的参数根据你的缓存后端不同而不同。</p>
<p>关于可用参数的一些信息可以在 <a class="reference internal" href="../topics/cache.html#cache-arguments"><span class="std std-ref">缓存参数</span></a> 文档中找到。更多信息，请查阅你的后端模块自己的文档。</p>
</div>
<div class="section" id="s-timeout">
<span id="s-std:setting-CACHES-TIMEOUT"></span><span id="timeout"></span><span id="std:setting-CACHES-TIMEOUT"></span><h4><code class="docutils literal notranslate"><span class="pre">TIMEOUT</span></code><a class="headerlink" href="#timeout" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">300</span></code></p>
<p>缓存条目被视为过期的秒数。如果这个设置的值是 <code class="docutils literal notranslate"><span class="pre">None</span></code>，缓存条目不会过期。</p>
</div>
<div class="section" id="s-version">
<span id="s-std:setting-CACHES-VERSION"></span><span id="version"></span><span id="std:setting-CACHES-VERSION"></span><h4><code class="docutils literal notranslate"><span class="pre">VERSION</span></code><a class="headerlink" href="#version" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">1</span></code></p>
<p>Django 服务器生成的缓存密钥的默认版本号。</p>
<p>查看 <a class="reference internal" href="../topics/cache.html#cache-versioning"><span class="std std-ref">缓存文档</span></a> 获取更多信息。</p>
</div>
</div>
<div class="section" id="s-cache-middleware-alias">
<span id="s-std:setting-CACHE_MIDDLEWARE_ALIAS"></span><span id="cache-middleware-alias"></span><span id="std:setting-CACHE_MIDDLEWARE_ALIAS"></span><h3><code class="docutils literal notranslate"><span class="pre">CACHE_MIDDLEWARE_ALIAS</span></code><a class="headerlink" href="#cache-middleware-alias" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'default'</span></code></p>
<p>用于 <a class="reference internal" href="../topics/cache.html#the-per-site-cache"><span class="std std-ref">缓存中间件</span></a> 的缓存连接。</p>
</div>
<div class="section" id="s-cache-middleware-key-prefix">
<span id="s-std:setting-CACHE_MIDDLEWARE_KEY_PREFIX"></span><span id="cache-middleware-key-prefix"></span><span id="std:setting-CACHE_MIDDLEWARE_KEY_PREFIX"></span><h3><code class="docutils literal notranslate"><span class="pre">CACHE_MIDDLEWARE_KEY_PREFIX</span></code><a class="headerlink" href="#cache-middleware-key-prefix" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>由 <a class="reference internal" href="../topics/cache.html#the-per-site-cache"><span class="std std-ref">缓存中间件</span></a> 生成的缓存密钥前缀的字符串。这个前缀与 <a class="reference internal" href="#std:setting-CACHES-KEY_PREFIX"><code class="xref std std-setting docutils literal notranslate"><span class="pre">KEY_PREFIX</span></code></a> 的配置结合在一起，而不是取代它。</p>
<p>参见 <a class="reference internal" href="../topics/cache.html"><span class="doc">Django 缓存框架</span></a>。</p>
</div>
<div class="section" id="s-cache-middleware-seconds">
<span id="s-std:setting-CACHE_MIDDLEWARE_SECONDS"></span><span id="cache-middleware-seconds"></span><span id="std:setting-CACHE_MIDDLEWARE_SECONDS"></span><h3><code class="docutils literal notranslate"><span class="pre">CACHE_MIDDLEWARE_SECONDS</span></code><a class="headerlink" href="#cache-middleware-seconds" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">600</span></code></p>
<p>默认为 <a class="reference internal" href="../topics/cache.html#the-per-site-cache"><span class="std std-ref">缓存中间件</span></a> 缓存页面的秒数。</p>
<p>参见 <a class="reference internal" href="../topics/cache.html"><span class="doc">Django 缓存框架</span></a>。</p>
<span class="target" id="settings-csrf"></span></div>
<div class="section" id="s-csrf-cookie-age">
<span id="s-std:setting-CSRF_COOKIE_AGE"></span><span id="csrf-cookie-age"></span><span id="std:setting-CSRF_COOKIE_AGE"></span><h3><code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_AGE</span></code><a class="headerlink" href="#csrf-cookie-age" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">31449600</span></code> （约 1 年，以秒为单位）</p>
<p>CSRF cookie 的寿命，以秒为单位。</p>
<p>设置长效过期时间的原因是为了避免在用户关闭浏览器或将某一页面作为书签，然后从浏览器缓存中加载该页面时出现问题。如果没有持久性 Cookie，这种情况下表单提交会失败。</p>
<p>一些浏览器（特别是 Internet Explorer）可能不允许使用持久性 cookie，或可能使 cookie jar 的索引在磁盘上损坏，从而导致 CSRF 保护检查（有时是间歇性的）失败。将此设置改为 <code class="docutils literal notranslate"><span class="pre">None</span></code>，以使用基于会话的 CSRF cookie，它将 cookie 保存在内存中，而不是持久性存储中。</p>
</div>
<div class="section" id="s-csrf-cookie-domain">
<span id="s-std:setting-CSRF_COOKIE_DOMAIN"></span><span id="csrf-cookie-domain"></span><span id="std:setting-CSRF_COOKIE_DOMAIN"></span><h3><code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_DOMAIN</span></code><a class="headerlink" href="#csrf-cookie-domain" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>设置 CSRF cookie 时要使用的域。 这对于允许跨子域请求被排除在正常的跨站点请求伪造保护之外是很有用的。 它应该设置为一个字符串，如 <code class="docutils literal notranslate"><span class="pre">&quot;.example.com&quot;</span></code>，以允许一个子域上的表单的 POST 请求被另一个子域的视图所接受。</p>
<p>请注意，这个配置的存在并不意味着 Django 的 CSRF 保护在默认情况下是安全的，不会受到跨子域的攻击——请参见 <a class="reference internal" href="csrf.html#csrf-limitations"><span class="std std-ref">CSRF 限制</span></a> 部分。</p>
</div>
<div class="section" id="s-csrf-cookie-httponly">
<span id="s-std:setting-CSRF_COOKIE_HTTPONLY"></span><span id="csrf-cookie-httponly"></span><span id="std:setting-CSRF_COOKIE_HTTPONLY"></span><h3><code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_HTTPONLY</span></code><a class="headerlink" href="#csrf-cookie-httponly" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>是否对 CSRF cookie 使用 <code class="docutils literal notranslate"><span class="pre">HttpOnly</span></code> 标志。如果设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，客户端的 JavaScript 将无法访问 CSRF cookie。</p>
<p>将 CSRF cookie 指定为 <code class="docutils literal notranslate"><span class="pre">HttpOnly</span></code> 并不能提供任何实际的保护，因为 CSRF 只是为了防止跨域攻击。如果攻击者可以通过 JavaScript 读取 cookie，就浏览器所知，他们已经在同一个域上了，所以他们可以做任何他们喜欢的事情。（XSS 是一个比 CSRF 更大的漏洞）。</p>
<p>虽然这种配置没有提供什么实际的好处，但有时也会被安全审计人员要求。</p>
<p>如果你启用了这个功能，并且需要通过 AJAX 请求发送 CSRF 标记的值，你的 JavaScript 必须 <a class="reference internal" href="csrf.html#acquiring-csrf-token-from-html"><span class="std std-ref">从隐藏的 CSRF 标记表单输入</span></a> 中提取值而不是 <a class="reference internal" href="csrf.html#acquiring-csrf-token-from-cookie"><span class="std std-ref">从 cookie</span></a>。</p>
<p>关于 <code class="docutils literal notranslate"><span class="pre">HttpOnly</span></code> 的详细信息，请参见 <a class="reference internal" href="#std:setting-SESSION_COOKIE_HTTPONLY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SESSION_COOKIE_HTTPONLY</span></code></a>。</p>
</div>
<div class="section" id="s-csrf-cookie-name">
<span id="s-std:setting-CSRF_COOKIE_NAME"></span><span id="csrf-cookie-name"></span><span id="std:setting-CSRF_COOKIE_NAME"></span><h3><code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_NAME</span></code><a class="headerlink" href="#csrf-cookie-name" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'csrftoken'</span></code></p>
<p>用于 CSRF 认证令牌的 cookie 的名称。这可以是任何你想要的名字（只要它与你的应用程序中的其他 cookie 名字不同）。参见 <a class="reference internal" href="csrf.html"><span class="doc">跨站请求伪造保护</span></a>。</p>
</div>
<div class="section" id="s-csrf-cookie-path">
<span id="s-std:setting-CSRF_COOKIE_PATH"></span><span id="csrf-cookie-path"></span><span id="std:setting-CSRF_COOKIE_PATH"></span><h3><code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_PATH</span></code><a class="headerlink" href="#csrf-cookie-path" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'/'</span></code></p>
<p>在 CSRF cookie 上设置的路径。这个路径应该与你的 Django 安装的 URL 路径相匹配，或者是该路径的父路径。</p>
<p>如果你有多个 Django 实例在同一个主机名下运行，这个功能很有用。他们可以使用不同的 cookie 路径，而且每个实例只能看到自己的 CSRF cookie。</p>
</div>
<div class="section" id="s-csrf-cookie-samesite">
<span id="s-std:setting-CSRF_COOKIE_SAMESITE"></span><span id="csrf-cookie-samesite"></span><span id="std:setting-CSRF_COOKIE_SAMESITE"></span><h3><code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_SAMESITE</span></code><a class="headerlink" href="#csrf-cookie-samesite" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'Lax'</span></code></p>
<p>CSRF cookie 上 <a class="reference external" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite">SameSite</a> 标志的值。该标志可防止在跨站点请求中发送 cookie。</p>
<p>关于 <code class="docutils literal notranslate"><span class="pre">SameSite</span></code> 的详细信息，请参见 <a class="reference internal" href="#std:setting-SESSION_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SESSION_COOKIE_SAMESITE</span></code></a>。</p>
<div class="versionchanged">
<span class="title">Changed in Django 3.1:</span> <p>允许设置 <code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_SAMESITE</span> <span class="pre">=</span> <span class="pre">'None'</span></code>。</p>
</div>
</div>
<div class="section" id="s-csrf-cookie-secure">
<span id="s-std:setting-CSRF_COOKIE_SECURE"></span><span id="csrf-cookie-secure"></span><span id="std:setting-CSRF_COOKIE_SECURE"></span><h3><code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_SECURE</span></code><a class="headerlink" href="#csrf-cookie-secure" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>是否为 CSRF cookie 使用安全 cookie。如果设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，cookie 将被标记为 <code class="docutils literal notranslate"><span class="pre">安全</span></code>，这意味着浏览器可以确保 cookie 只在 HTTPS 连接下发送。</p>
</div>
<div class="section" id="s-csrf-use-sessions">
<span id="s-std:setting-CSRF_USE_SESSIONS"></span><span id="csrf-use-sessions"></span><span id="std:setting-CSRF_USE_SESSIONS"></span><h3><code class="docutils literal notranslate"><span class="pre">CSRF_USE_SESSIONS</span></code><a class="headerlink" href="#csrf-use-sessions" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>是否将 CSRF 标记存储在用户的会话中，而不是 cookie 中。这需要使用 <code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.session</span></code>。</p>
<p>将 CSRF 令牌存储在 cookie 中（Django 的默认值）是安全的，但将其存储在 session 中是其他 Web 框架的常见做法，因此有时会被安全审计人员要求。</p>
<p>由于 <a class="reference internal" href="views.html#error-views"><span class="std std-ref">默认错误视图</span></a> 需要CSRF令牌，所以 <code class="xref py py-class docutils literal notranslate"><span class="pre">SessionMiddleware</span></code> 必须出现在 <a class="reference internal" href="#std:setting-MIDDLEWARE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MIDDLEWARE</span></code></a> 中，在任何可能引发异常以触发错误视图的中间件（如 <a class="reference internal" href="exceptions.html#django.core.exceptions.PermissionDenied" title="django.core.exceptions.PermissionDenied"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PermissionDenied</span></code></a>）之前，如果你正在使用 <code class="docutils literal notranslate"><span class="pre">CSRF_USE_SESSIONS</span></code>。参见 <a class="reference internal" href="middleware.html#middleware-ordering"><span class="std std-ref">中间件顺序</span></a>。</p>
</div>
<div class="section" id="s-csrf-failure-view">
<span id="s-std:setting-CSRF_FAILURE_VIEW"></span><span id="csrf-failure-view"></span><span id="std:setting-CSRF_FAILURE_VIEW"></span><h3><code class="docutils literal notranslate"><span class="pre">CSRF_FAILURE_VIEW</span></code><a class="headerlink" href="#csrf-failure-view" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'django.views.csrf.csrf_failure'</span></code></p>
<p>当传入的请求被 <a class="reference internal" href="csrf.html"><span class="doc">CSRF 保护</span></a> 拒绝时，要使用的视图函数的点分隔路径。该函数应具有以下签名：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">csrf_failure</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">reason</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
    <span class="o">...</span>
</pre></div>
</div>
<p>其中 <code class="docutils literal notranslate"><span class="pre">reason</span></code> 是一个简短的消息（针对开发者或日志记录，而不是针对终端用户），表示请求被拒绝的原因，它应该返回一个 <a class="reference internal" href="request-response.html#django.http.HttpResponseForbidden" title="django.http.HttpResponseForbidden"><code class="xref py py-class docutils literal notranslate"><span class="pre">HttpResponseForbidden</span></code></a>。</p>
<p><code class="docutils literal notranslate"><span class="pre">django.views.csrf.csrf_failure()</span></code> 接受一个额外的 <code class="docutils literal notranslate"><span class="pre">template_name</span></code> 参数，默认为 <code class="docutils literal notranslate"><span class="pre">'403_csrf.html'</span></code>。如果存在该名称的模板，它将被用来渲染页面。</p>
</div>
<div class="section" id="s-csrf-header-name">
<span id="s-std:setting-CSRF_HEADER_NAME"></span><span id="csrf-header-name"></span><span id="std:setting-CSRF_HEADER_NAME"></span><h3><code class="docutils literal notranslate"><span class="pre">CSRF_HEADER_NAME</span></code><a class="headerlink" href="#csrf-header-name" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'HTTP_X_CSRFTOKEN'</span></code></p>
<p>用于 CSRF 认证的请求头的名称。</p>
<p>与 <code class="docutils literal notranslate"><span class="pre">request.META</span></code> 中的其他 HTTP 头文件一样，从服务器接收到的头文件名通过将所有字符转换为大写字母，用下划线代替任何连字符，并在名称中添加 <code class="docutils literal notranslate"><span class="pre">'HTTP_'</span></code> 前缀进行规范化。例如，如果你的客户端发送了一个 <code class="docutils literal notranslate"><span class="pre">'X-XSRF-TOKEN'</span></code> 头，配置应该是 <code class="docutils literal notranslate"><span class="pre">'HTTP_X_XSRF_TOKEN'</span></code>。</p>
</div>
<div class="section" id="s-csrf-trusted-origins">
<span id="s-std:setting-CSRF_TRUSTED_ORIGINS"></span><span id="csrf-trusted-origins"></span><span id="std:setting-CSRF_TRUSTED_ORIGINS"></span><h3><code class="docutils literal notranslate"><span class="pre">CSRF_TRUSTED_ORIGINS</span></code><a class="headerlink" href="#csrf-trusted-origins" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>不安全请求（例如 <code class="docutils literal notranslate"><span class="pre">POST</span></code>）的可信来源主机列表。对于 <a class="reference internal" href="request-response.html#django.http.HttpRequest.is_secure" title="django.http.HttpRequest.is_secure"><code class="xref py py-meth docutils literal notranslate"><span class="pre">可靠</span></code></a> 的不安全请求，Django 的 CSRF 保护要求该请求的 <code class="docutils literal notranslate"><span class="pre">Referer</span></code> 头必须与 <code class="docutils literal notranslate"><span class="pre">Host</span></code> 头中的来源匹配。例如，这可以防止来自 <code class="docutils literal notranslate"><span class="pre">subdomain.example.com</span></code> 的 <code class="docutils literal notranslate"><span class="pre">POST</span></code> 请求对 <code class="docutils literal notranslate"><span class="pre">api.example.com</span></code> 成功。如果你需要通过 HTTPS 的跨源不安全请求，继续这个例子，在这个列表中添加 <code class="docutils literal notranslate"><span class="pre">&quot;subdomain.example.com&quot;`</span></code>。该设置还支持子域，所以你可以添加 <code class="docutils literal notranslate"><span class="pre">&quot;.example.com&quot;</span></code>，例如，允许从 <code class="docutils literal notranslate"><span class="pre">example.com</span></code> 的所有子域访问。</p>
</div>
<div class="section" id="s-databases">
<span id="s-std:setting-DATABASES"></span><span id="databases"></span><span id="std:setting-DATABASES"></span><h3><code class="docutils literal notranslate"><span class="pre">DATABASES</span></code><a class="headerlink" href="#databases" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">{}</span></code> （空字典）</p>
<p>一个包含所有数据库配置的字典，用于 Django。它是一个嵌套的字典，其内容是将一个数据库别名映射到一个包含单个数据库选项的字典中。</p>
<p><a class="reference internal" href="#std:setting-DATABASES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATABASES</span></code></a> 配置必须设置一个 <code class="docutils literal notranslate"><span class="pre">default</span></code> 数据库；也可以指定任何数量的其他数据库。</p>
<p>最简单的配置文件是使用 SQLite 的单数据库配置。可以通过以下方式进行配置：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">DATABASES</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">&#39;default&#39;</span><span class="p">:</span> <span class="p">{</span>
        <span class="s1">&#39;ENGINE&#39;</span><span class="p">:</span> <span class="s1">&#39;django.db.backends.sqlite3&#39;</span><span class="p">,</span>
        <span class="s1">&#39;NAME&#39;</span><span class="p">:</span> <span class="s1">&#39;mydatabase&#39;</span><span class="p">,</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>当连接到其他数据库后端时，如 MariaDB、MySQL、Oracle 或 PostgreSQL，将需要额外的连接参数。请参阅下面的 <a class="reference internal" href="#std:setting-DATABASE-ENGINE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">ENGINE</span></code></a> 配置，了解如何指定其他数据库类型。这个例子是针对 PostgreSQL：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">DATABASES</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">&#39;default&#39;</span><span class="p">:</span> <span class="p">{</span>
        <span class="s1">&#39;ENGINE&#39;</span><span class="p">:</span> <span class="s1">&#39;django.db.backends.postgresql&#39;</span><span class="p">,</span>
        <span class="s1">&#39;NAME&#39;</span><span class="p">:</span> <span class="s1">&#39;mydatabase&#39;</span><span class="p">,</span>
        <span class="s1">&#39;USER&#39;</span><span class="p">:</span> <span class="s1">&#39;mydatabaseuser&#39;</span><span class="p">,</span>
        <span class="s1">&#39;PASSWORD&#39;</span><span class="p">:</span> <span class="s1">&#39;mypassword&#39;</span><span class="p">,</span>
        <span class="s1">&#39;HOST&#39;</span><span class="p">:</span> <span class="s1">&#39;127.0.0.1&#39;</span><span class="p">,</span>
        <span class="s1">&#39;PORT&#39;</span><span class="p">:</span> <span class="s1">&#39;5432&#39;</span><span class="p">,</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>以下是更复杂配置可能需要的内部选项：</p>
<div class="section" id="s-atomic-requests">
<span id="s-std:setting-DATABASE-ATOMIC_REQUESTS"></span><span id="atomic-requests"></span><span id="std:setting-DATABASE-ATOMIC_REQUESTS"></span><h4><code class="docutils literal notranslate"><span class="pre">ATOMIC_REQUESTS</span></code><a class="headerlink" href="#atomic-requests" title="永久链接至标题">¶</a></h4>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>将此设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，以将每个视图包裹在这个数据库的事务中。参见 <a class="reference internal" href="../topics/db/transactions.html#tying-transactions-to-http-requests"><span class="std std-ref">连结事务与 HTTP 请求</span></a>。</p>
</div>
<div class="section" id="s-autocommit">
<span id="s-std:setting-DATABASE-AUTOCOMMIT"></span><span id="autocommit"></span><span id="std:setting-DATABASE-AUTOCOMMIT"></span><h4><code class="docutils literal notranslate"><span class="pre">AUTOCOMMIT</span></code><a class="headerlink" href="#autocommit" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">True</span></code></p>
<p>如果你想 <a class="reference internal" href="../topics/db/transactions.html#deactivate-transaction-management"><span class="std std-ref">禁用 Django 的事务管理</span></a> 并实现你自己的事务管理，请将此设置为 <code class="docutils literal notranslate"><span class="pre">False</span></code>。</p>
</div>
<div class="section" id="s-engine">
<span id="s-std:setting-DATABASE-ENGINE"></span><span id="engine"></span><span id="std:setting-DATABASE-ENGINE"></span><h4><code class="docutils literal notranslate"><span class="pre">ENGINE</span></code><a class="headerlink" href="#engine" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>要使用的数据库后端。内置的数据库后端有：</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">'django.db.backends.postgresql'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.db.backends.mysql'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.db.backends.sqlite3'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.db.backends.oracle'</span></code></li>
</ul>
<p>你可以通过将 <code class="docutils literal notranslate"><span class="pre">ENGINE</span></code> 设置为一个完全限定的路径（例如： <code class="docutils literal notranslate"><span class="pre">mypackage.backends.whatever</span></code>），来使用一个不在 Django 中的数据库后端。</p>
</div>
<div class="section" id="s-host">
<span id="s-std:setting-HOST"></span><span id="host"></span><span id="std:setting-HOST"></span><h4><code class="docutils literal notranslate"><span class="pre">HOST</span></code><a class="headerlink" href="#host" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>连接到数据库时使用的主机。空字符串表示本地主机。不用于 SQLite。</p>
<p>如果这个值以斜线（<code class="docutils literal notranslate"><span class="pre">'/'</span></code>）开头，并且你正在使用 MySQL，MySQL 将通过 Unix 套接字连接到指定的套接字。例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="s2">&quot;HOST&quot;</span><span class="p">:</span> <span class="s1">&#39;/var/run/mysql&#39;</span>
</pre></div>
</div>
<p>如果你使用的是 MySQL，并且这个值 <em>没有</em> 以斜线开头，那么这个值被认为是主机。</p>
<p>如果你使用的是 PostgreSQL，默认情况下（空 <a class="reference internal" href="#std:setting-HOST"><code class="xref std std-setting docutils literal notranslate"><span class="pre">HOST</span></code></a>），与数据库的连接是通过 UNIX 域套接字（<code class="docutils literal notranslate"><span class="pre">pg_hba.conf</span></code> 中的 'local' ）完成的。如果你的 UNIX 域套接字不在标准位置，请使用 <code class="docutils literal notranslate"><span class="pre">postgresql.conf</span></code> 中的 <code class="docutils literal notranslate"><span class="pre">unix_socket_directory</span></code> 的相同值。如果你想通过 TCP 套接字连接，将 <a class="reference internal" href="#std:setting-HOST"><code class="xref std std-setting docutils literal notranslate"><span class="pre">HOST</span></code></a> 设置为 'localhost' 或 '127.0.0.1'（<code class="docutils literal notranslate"><span class="pre">pg_hba.conf</span></code> 中的 'host' 行）。在 Windows 上，你应该总是定义 <a class="reference internal" href="#std:setting-HOST"><code class="xref std std-setting docutils literal notranslate"><span class="pre">HOST</span></code></a>，因为 UNIX 域套接字是不可用的。</p>
</div>
<div class="section" id="s-name">
<span id="s-std:setting-NAME"></span><span id="name"></span><span id="std:setting-NAME"></span><h4><code class="docutils literal notranslate"><span class="pre">NAME</span></code><a class="headerlink" href="#name" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>要使用的数据库的名称。对于 SQLite，它是数据库文件的完整路径。当指定路径时，总是使用斜线，即使在 Windows 上也是如此（例如 <code class="docutils literal notranslate"><span class="pre">C:/homes/user/mysite/sqlite3.db</span></code>）。</p>
</div>
<div class="section" id="s-conn-max-age">
<span id="s-std:setting-CONN_MAX_AGE"></span><span id="conn-max-age"></span><span id="std:setting-CONN_MAX_AGE"></span><h4><code class="docutils literal notranslate"><span class="pre">CONN_MAX_AGE</span></code><a class="headerlink" href="#conn-max-age" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">0</span></code></p>
<p>一个数据库连接的寿命，以秒为整数。使用 <code class="docutils literal notranslate"><span class="pre">0</span></code> 在每次请求结束时关闭数据库连接——这是 Django 的历史行为，使用 <code class="docutils literal notranslate"><span class="pre">None</span></code> 则是无限的持久连接。</p>
</div>
<div class="section" id="s-std:setting-OPTIONS">
<span id="s-id1"></span><span id="std:setting-OPTIONS"></span><span id="id1"></span><h4><code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code><a class="headerlink" href="#std:setting-OPTIONS" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">{}</span></code> （空字典）</p>
<p>连接到数据库时要使用的额外参数。可用的参数根据你的数据库后端不同而不同。</p>
<p>关于可用参数的一些信息可以在 <a class="reference internal" href="databases.html"><span class="doc">数据库后端</span></a> 文档中找到。更多信息，请查阅你的后端模块自己的文档。</p>
</div>
<div class="section" id="s-password">
<span id="s-std:setting-PASSWORD"></span><span id="password"></span><span id="std:setting-PASSWORD"></span><h4><code class="docutils literal notranslate"><span class="pre">PASSWORD</span></code><a class="headerlink" href="#password" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>连接到数据库时使用的密码。不用于 SQLite。</p>
</div>
<div class="section" id="s-port">
<span id="s-std:setting-PORT"></span><span id="port"></span><span id="std:setting-PORT"></span><h4><code class="docutils literal notranslate"><span class="pre">PORT</span></code><a class="headerlink" href="#port" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>连接到数据库时要使用的端口。空字符串表示默认端口。不用于 SQLite。</p>
</div>
<div class="section" id="s-time-zone">
<span id="s-std:setting-DATABASE-TIME_ZONE"></span><span id="time-zone"></span><span id="std:setting-DATABASE-TIME_ZONE"></span><h4><code class="docutils literal notranslate"><span class="pre">TIME_ZONE</span></code><a class="headerlink" href="#time-zone" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>代表该数据库连接时区的字符串或 <code class="docutils literal notranslate"><span class="pre">None</span></code>。<a class="reference internal" href="#std:setting-DATABASES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATABASES</span></code></a> 配置的这个内部选项与一般的 <a class="reference internal" href="#std:setting-TIME_ZONE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_ZONE</span></code></a> 配置接受相同的值。</p>
<p>当 <a class="reference internal" href="#std:setting-USE_TZ"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_TZ</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 且设置了这个选项时，从数据库中读取日期时间会返回这个时区的感知日期时间，而不是 UTC。当 <a class="reference internal" href="#std:setting-USE_TZ"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_TZ</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code> 时，设置该选项是错误的。</p>
<ul>
<li><p class="first">如果数据库后端不支持时区（如 SQLite、MySQL、Oracle），如果设置了这个选项，Django 会根据这个选项以当地时间读写日期，如果没有设置，则以 UTC 时间读写。</p>
<p>改变连接时区会改变从数据库中读取和写入日期的方式。</p>
<ul class="simple">
<li>如果 Django 管理数据库，而你又没有很强的理由，你应该不设置这个选项。最好用 UTC 存储日期时间，因为这样可以避免在夏令时变化时出现模糊不清或不存在的日期时间。另外，以 UTC 接收日期时间可以使日期时间的运算变得简单——不需要使用 pytz 提供的 <code class="docutils literal notranslate"><span class="pre">normalize()</span></code> 方法。</li>
<li>如果你连接的第三方数据库以当地时间而不是 UTC 存储日期，那么你必须将这个选项设置为合适的时区。同样，如果 Django 管理数据库，但第三方系统连接到同一个数据库，并希望找到当地时间的日期，那么你必须设置这个选项。</li>
</ul>
</li>
<li><p class="first">如果数据库后端支持时区（如 PostgreSQL），很少需要 <code class="docutils literal notranslate"><span class="pre">TIME_ZONE</span></code> 选项。它可以在任何时候改变；数据库会负责将日期时间转换为所需的时区。</p>
<p>设置数据库连接的时区对于运行涉及数据库提供的日期／时间函数的原始 SQL 查询（如 <code class="docutils literal notranslate"><span class="pre">date_trunc</span></code>）可能很有用，因为其结果取决于时区。</p>
<p>然而，这有一个缺点：以本地时间接收所有的日期时间，使得日期时间的运算变得更加棘手——你必须在每次操作后调用 pytz 提供的 <code class="docutils literal notranslate"><span class="pre">normalize()</span></code> 方法。</p>
<p>考虑在原始 SQL 查询中使用 <code class="docutils literal notranslate"><span class="pre">AT</span> <span class="pre">TIME</span> <span class="pre">ZONE</span></code> 明确转换为当地时间，而不是设置 <code class="docutils literal notranslate"><span class="pre">TIME_ZONE</span></code> 选项。</p>
</li>
</ul>
<div class="versionchanged">
<span class="title">Changed in Django 3.1:</span> <p>当数据库后台支持时区时，允许使用这个选项。</p>
</div>
</div>
<div class="section" id="s-disable-server-side-cursors">
<span id="s-std:setting-DATABASE-DISABLE_SERVER_SIDE_CURSORS"></span><span id="disable-server-side-cursors"></span><span id="std:setting-DATABASE-DISABLE_SERVER_SIDE_CURSORS"></span><h4><code class="docutils literal notranslate"><span class="pre">DISABLE_SERVER_SIDE_CURSORS</span></code><a class="headerlink" href="#disable-server-side-cursors" title="永久链接至标题">¶</a></h4>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>如果你想通过 <a class="reference internal" href="models/querysets.html#django.db.models.query.QuerySet.iterator" title="django.db.models.query.QuerySet.iterator"><code class="xref py py-meth docutils literal notranslate"><span class="pre">QuerySet.iterator()</span></code></a> 禁用服务器端游标的使用，请将其设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>。 <a class="reference internal" href="databases.html#transaction-pooling-server-side-cursors"><span class="std std-ref">事务池和服务器端游标</span></a> 描述了使用情况。</p>
<p>这是 PostgreSQL 特有的配置。</p>
</div>
<div class="section" id="s-user">
<span id="s-std:setting-USER"></span><span id="user"></span><span id="std:setting-USER"></span><h4><code class="docutils literal notranslate"><span class="pre">USER</span></code><a class="headerlink" href="#user" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>连接数据库时要使用的用户名。不用于 SQLite。</p>
</div>
<div class="section" id="s-test">
<span id="s-std:setting-DATABASE-TEST"></span><span id="test"></span><span id="std:setting-DATABASE-TEST"></span><h4><code class="docutils literal notranslate"><span class="pre">TEST</span></code><a class="headerlink" href="#test" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">{}</span></code> （空字典）</p>
<p>测试数据库的设置字典；关于测试数据库的创建和使用的更多细节，见 <a class="reference internal" href="../topics/testing/overview.html#the-test-database"><span class="std std-ref">测试数据库</span></a>。</p>
<p>下面是一个测试数据库配置的例子：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">DATABASES</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">&#39;default&#39;</span><span class="p">:</span> <span class="p">{</span>
        <span class="s1">&#39;ENGINE&#39;</span><span class="p">:</span> <span class="s1">&#39;django.db.backends.postgresql&#39;</span><span class="p">,</span>
        <span class="s1">&#39;USER&#39;</span><span class="p">:</span> <span class="s1">&#39;mydatabaseuser&#39;</span><span class="p">,</span>
        <span class="s1">&#39;NAME&#39;</span><span class="p">:</span> <span class="s1">&#39;mydatabase&#39;</span><span class="p">,</span>
        <span class="s1">&#39;TEST&#39;</span><span class="p">:</span> <span class="p">{</span>
            <span class="s1">&#39;NAME&#39;</span><span class="p">:</span> <span class="s1">&#39;mytestdatabase&#39;</span><span class="p">,</span>
        <span class="p">},</span>
    <span class="p">},</span>
<span class="p">}</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">TEST</span></code> 字典中的下列键可供使用：</p>
<div class="section" id="s-charset">
<span id="s-std:setting-TEST_CHARSET"></span><span id="charset"></span><span id="std:setting-TEST_CHARSET"></span><h5><code class="docutils literal notranslate"><span class="pre">CHARSET</span></code><a class="headerlink" href="#charset" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>用于创建测试数据库的字符集编码。这个字符串的值是直接传递给数据库的，所以它的格式是特定于后端的。</p>
<p>由 <a class="reference external" href="https://www.postgresql.org/docs/current/multibyte.html">PostgreSQL</a> （<code class="docutils literal notranslate"><span class="pre">postgresql</span></code>）和 <a class="reference external" href="https://dev.mysql.com/doc/refman/en/charset-charsets.html">MySQL</a> （<code class="docutils literal notranslate"><span class="pre">mysql</span></code>）后端支持。</p>
</div>
<div class="section" id="s-collation">
<span id="s-std:setting-TEST_COLLATION"></span><span id="collation"></span><span id="std:setting-TEST_COLLATION"></span><h5><code class="docutils literal notranslate"><span class="pre">COLLATION</span></code><a class="headerlink" href="#collation" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>创建测试数据库时要使用的字符序。这个值是直接传递给后端的，所以它的格式是后端特定的。</p>
<p>仅支持 <code class="docutils literal notranslate"><span class="pre">mysql</span></code> 后端（详见 <a class="reference external" href="https://dev.mysql.com/doc/refman/en/charset-charsets.html">MySQL 手册</a> ）。</p>
</div>
<div class="section" id="s-dependencies">
<span id="s-std:setting-TEST_DEPENDENCIES"></span><span id="dependencies"></span><span id="std:setting-TEST_DEPENDENCIES"></span><h5><code class="docutils literal notranslate"><span class="pre">DEPENDENCIES</span></code><a class="headerlink" href="#dependencies" title="永久链接至标题">¶</a></h5>
<p>默认：<code class="docutils literal notranslate"><span class="pre">['default']</span></code>，适用于除 <code class="docutils literal notranslate"><span class="pre">default</span></code> 以外的所有数据库，后者没有依赖性。</p>
<p>数据库的创建顺序依赖性。详见 <a class="reference internal" href="../topics/testing/advanced.html#topics-testing-creation-dependencies"><span class="std std-ref">控制测试数据库的创建顺序</span></a> 的文档。</p>
</div>
<div class="section" id="s-migrate">
<span id="s-std:setting-TEST_MIGRATE"></span><span id="migrate"></span><span id="std:setting-TEST_MIGRATE"></span><h5><code class="docutils literal notranslate"><span class="pre">MIGRATE</span></code><a class="headerlink" href="#migrate" title="永久链接至标题">¶</a></h5>
<div class="versionadded">
<span class="title">New in Django 3.1.</span> </div>
<p>默认： <code class="docutils literal notranslate"><span class="pre">True</span></code></p>
<p>当设置为 <code class="docutils literal notranslate"><span class="pre">False</span></code> 时，在创建测试数据库时不会运行迁移。这类似于在 <a class="reference internal" href="#std:setting-MIGRATION_MODULES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MIGRATION_MODULES</span></code></a> 中设置 <code class="docutils literal notranslate"><span class="pre">None</span></code> 作为一个值，但适用于所有应用程序。</p>
</div>
<div class="section" id="s-mirror">
<span id="s-std:setting-TEST_MIRROR"></span><span id="mirror"></span><span id="std:setting-TEST_MIRROR"></span><h5><code class="docutils literal notranslate"><span class="pre">MIRROR</span></code><a class="headerlink" href="#mirror" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>在测试过程中，该数据库应该镜像的数据库的别名。</p>
<p>该配置允许测试多个数据库的主／副本（某些数据库称为主／从）配置。详情请参见 <a class="reference internal" href="../topics/testing/advanced.html#topics-testing-primaryreplica"><span class="std std-ref">测试主／副本配置</span></a> 的文档。</p>
</div>
<div class="section" id="s-std:setting-TEST_NAME">
<span id="s-id2"></span><span id="std:setting-TEST_NAME"></span><span id="id2"></span><h5><code class="docutils literal notranslate"><span class="pre">NAME</span></code><a class="headerlink" href="#std:setting-TEST_NAME" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>运行测试套件时要使用的数据库名称。</p>
<p>如果 SQLite 数据库引擎使用默认值（<code class="docutils literal notranslate"><span class="pre">None</span></code>），则测试将使用内存常驻数据库。对于所有其他数据库引擎，测试数据库将使用 <code class="docutils literal notranslate"><span class="pre">'test_'</span> <span class="pre">+</span> <span class="pre">DATABASE_NAME</span></code> 的名称。</p>
<p>查看 <a class="reference internal" href="../topics/testing/overview.html#the-test-database"><span class="std std-ref">测试数据库</span></a>。</p>
</div>
<div class="section" id="s-serialize">
<span id="s-std:setting-TEST_SERIALIZE"></span><span id="serialize"></span><span id="std:setting-TEST_SERIALIZE"></span><h5><code class="docutils literal notranslate"><span class="pre">SERIALIZE</span></code><a class="headerlink" href="#serialize" title="永久链接至标题">¶</a></h5>
<p>布尔值，用于控制默认的测试运行器是否在运行测试之前将数据库序列化为内存中的 JSON 字符串（如果没有事务，用于在测试之间恢复数据库状态）。如果你没有任何带有 <a class="reference internal" href="../topics/testing/overview.html#test-case-serialized-rollback"><span class="std std-ref">serialized_rollback=True</span></a> 的测试类，你可以将其设置为 <code class="docutils literal notranslate"><span class="pre">False</span></code> 以加快创建时间。</p>
</div>
<div class="section" id="s-template">
<span id="s-std:setting-TEST_TEMPLATE"></span><span id="template"></span><span id="std:setting-TEST_TEMPLATE"></span><h5><code class="docutils literal notranslate"><span class="pre">TEMPLATE</span></code><a class="headerlink" href="#template" title="永久链接至标题">¶</a></h5>
<p>这是 PostgreSQL 特有的配置。</p>
<p><a class="reference external" href="https://www.postgresql.org/docs/current/sql-createdatabase.html">template</a> 的名称（例如 <code class="docutils literal notranslate"><span class="pre">'template0'</span></code>），用于创建测试数据库。</p>
</div>
<div class="section" id="s-create-db">
<span id="s-std:setting-TEST_CREATE"></span><span id="create-db"></span><span id="std:setting-TEST_CREATE"></span><h5><code class="docutils literal notranslate"><span class="pre">CREATE_DB</span></code><a class="headerlink" href="#create-db" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">True</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p>如果设置为 <code class="docutils literal notranslate"><span class="pre">False</span></code>，测试表空间不会在测试开始时自动创建，也不会在测试结束时删除。</p>
</div>
<div class="section" id="s-create-user">
<span id="s-std:setting-TEST_USER_CREATE"></span><span id="create-user"></span><span id="std:setting-TEST_USER_CREATE"></span><h5><code class="docutils literal notranslate"><span class="pre">CREATE_USER</span></code><a class="headerlink" href="#create-user" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">True</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p>如果设置为 <code class="docutils literal notranslate"><span class="pre">False</span></code>，测试用户不会在测试开始时自动创建，也不会在测试结束时删除。</p>
</div>
<div class="section" id="s-std:setting-TEST_USER">
<span id="s-id4"></span><span id="std:setting-TEST_USER"></span><span id="id4"></span><h5><code class="docutils literal notranslate"><span class="pre">USER</span></code><a class="headerlink" href="#std:setting-TEST_USER" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p>连接到 Oracle 数据库时使用的用户名。如果没有提供，Django 将使用 <code class="docutils literal notranslate"><span class="pre">'test_'</span> <span class="pre">+</span> <span class="pre">USER</span></code>。</p>
</div>
<div class="section" id="s-std:setting-TEST_PASSWD">
<span id="s-id5"></span><span id="std:setting-TEST_PASSWD"></span><span id="id5"></span><h5><code class="docutils literal notranslate"><span class="pre">PASSWORD</span></code><a class="headerlink" href="#std:setting-TEST_PASSWD" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p>连接到 Oracle 数据库时使用的密码。如果没有提供，Django 会随机生成一个密码。</p>
</div>
<div class="section" id="s-oracle-managed-files">
<span id="s-std:setting-TEST_ORACLE_MANAGED_FILES"></span><span id="oracle-managed-files"></span><span id="std:setting-TEST_ORACLE_MANAGED_FILES"></span><h5><code class="docutils literal notranslate"><span class="pre">ORACLE_MANAGED_FILES</span></code><a class="headerlink" href="#oracle-managed-files" title="永久链接至标题">¶</a></h5>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p><a class="reference internal" href="#std:setting-DATAFILE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATAFILE</span></code></a> 和 <a class="reference internal" href="#std:setting-DATAFILE_TMP"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATAFILE_TMP</span></code></a> 将被忽略。</p>
</div>
<div class="section" id="s-tblspace">
<span id="s-std:setting-TEST_TBLSPACE"></span><span id="tblspace"></span><span id="std:setting-TEST_TBLSPACE"></span><h5><code class="docutils literal notranslate"><span class="pre">TBLSPACE</span></code><a class="headerlink" href="#tblspace" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p>运行测试时使用的表空间的名称。如果没有提供，Django 将使用 <code class="docutils literal notranslate"><span class="pre">'test_'</span> <span class="pre">+</span> <span class="pre">USER</span></code>。</p>
</div>
<div class="section" id="s-tblspace-tmp">
<span id="s-std:setting-TEST_TBLSPACE_TMP"></span><span id="tblspace-tmp"></span><span id="std:setting-TEST_TBLSPACE_TMP"></span><h5><code class="docutils literal notranslate"><span class="pre">TBLSPACE_TMP</span></code><a class="headerlink" href="#tblspace-tmp" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p>运行测试时使用的临时表空间的名称。如果没有提供，Django 将使用 <code class="docutils literal notranslate"><span class="pre">'test_'</span> <span class="pre">+</span> <span class="pre">USER</span> <span class="pre">+</span> <span class="pre">'_temp'</span></code>。</p>
</div>
<div class="section" id="s-datafile">
<span id="s-std:setting-DATAFILE"></span><span id="datafile"></span><span id="std:setting-DATAFILE"></span><h5><code class="docutils literal notranslate"><span class="pre">DATAFILE</span></code><a class="headerlink" href="#datafile" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p>TBLSPACE 要使用的数据文件名。如果没有提供，Django 将使用 <code class="docutils literal notranslate"><span class="pre">TBLSPACE</span> <span class="pre">+</span> <span class="pre">'.dbf'</span></code>。</p>
</div>
<div class="section" id="s-datafile-tmp">
<span id="s-std:setting-DATAFILE_TMP"></span><span id="datafile-tmp"></span><span id="std:setting-DATAFILE_TMP"></span><h5><code class="docutils literal notranslate"><span class="pre">DATAFILE_TMP</span></code><a class="headerlink" href="#datafile-tmp" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p>TBLSPACE_TMP 的数据文件名。如果没有提供，Django 将使用 <code class="docutils literal notranslate"><span class="pre">TBLSPACE_TMP</span> <span class="pre">+</span> <span class="pre">'.dbf'</span></code>。</p>
</div>
<div class="section" id="s-datafile-maxsize">
<span id="s-std:setting-DATAFILE_MAXSIZE"></span><span id="datafile-maxsize"></span><span id="std:setting-DATAFILE_MAXSIZE"></span><h5><code class="docutils literal notranslate"><span class="pre">DATAFILE_MAXSIZE</span></code><a class="headerlink" href="#datafile-maxsize" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'500M'</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p>DATAFILE 允许增长的最大尺寸。</p>
</div>
<div class="section" id="s-datafile-tmp-maxsize">
<span id="s-std:setting-DATAFILE_TMP_MAXSIZE"></span><span id="datafile-tmp-maxsize"></span><span id="std:setting-DATAFILE_TMP_MAXSIZE"></span><h5><code class="docutils literal notranslate"><span class="pre">DATAFILE_TMP_MAXSIZE</span></code><a class="headerlink" href="#datafile-tmp-maxsize" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'500M'</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p>DATAFILE_TMP 允许增长的最大尺寸。</p>
</div>
<div class="section" id="s-datafile-size">
<span id="s-std:setting-DATAFILE_SIZE"></span><span id="datafile-size"></span><span id="std:setting-DATAFILE_SIZE"></span><h5><code class="docutils literal notranslate"><span class="pre">DATAFILE_SIZE</span></code><a class="headerlink" href="#datafile-size" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'50M'</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p>DATAFILE 的初始大小。</p>
</div>
<div class="section" id="s-datafile-tmp-size">
<span id="s-std:setting-DATAFILE_TMP_SIZE"></span><span id="datafile-tmp-size"></span><span id="std:setting-DATAFILE_TMP_SIZE"></span><h5><code class="docutils literal notranslate"><span class="pre">DATAFILE_TMP_SIZE</span></code><a class="headerlink" href="#datafile-tmp-size" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'50M'</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p>DATAFILE_TMP 的初始大小。</p>
</div>
<div class="section" id="s-datafile-extsize">
<span id="s-std:setting-DATAFILE_EXTSIZE"></span><span id="datafile-extsize"></span><span id="std:setting-DATAFILE_EXTSIZE"></span><h5><code class="docutils literal notranslate"><span class="pre">DATAFILE_EXTSIZE</span></code><a class="headerlink" href="#datafile-extsize" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'25M'</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p>当需要更多空间时，DATAFILE 的扩展量。</p>
</div>
<div class="section" id="s-datafile-tmp-extsize">
<span id="s-std:setting-DATAFILE_TMP_EXTSIZE"></span><span id="datafile-tmp-extsize"></span><span id="std:setting-DATAFILE_TMP_EXTSIZE"></span><h5><code class="docutils literal notranslate"><span class="pre">DATAFILE_TMP_EXTSIZE</span></code><a class="headerlink" href="#datafile-tmp-extsize" title="永久链接至标题">¶</a></h5>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'25M'</span></code></p>
<p>这是 Oracle 特有的配置。</p>
<p>当需要更多空间时，DATAFILE_TMP 的扩展量。</p>
</div>
</div>
</div>
<div class="section" id="s-data-upload-max-memory-size">
<span id="s-std:setting-DATA_UPLOAD_MAX_MEMORY_SIZE"></span><span id="data-upload-max-memory-size"></span><span id="std:setting-DATA_UPLOAD_MAX_MEMORY_SIZE"></span><h3><code class="docutils literal notranslate"><span class="pre">DATA_UPLOAD_MAX_MEMORY_SIZE</span></code><a class="headerlink" href="#data-upload-max-memory-size" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">2621440</span></code> （即 2.5 MB）。</p>
<p>请求体在引发 <a class="reference internal" href="exceptions.html#django.core.exceptions.SuspiciousOperation" title="django.core.exceptions.SuspiciousOperation"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SuspiciousOperation</span></code></a> （<code class="docutils literal notranslate"><span class="pre">RequestDataTooBig</span></code>）之前的最大字节数。这个检查是在访问 <code class="docutils literal notranslate"><span class="pre">request.body</span></code> 或 <code class="docutils literal notranslate"><span class="pre">request.POST</span></code> 时进行的，是根据请求的总大小计算的，不包括任何文件上传数据。你可以将其设置为 <code class="docutils literal notranslate"><span class="pre">None</span></code> 以禁用该检查。预计会收到非常大的上传表单的应用程序应该调整这个配置。</p>
<p>请求数据的数量与处理请求和填充 GET 和 POST 字典所需的内存量相关。如果不进行检查，大的请求可能会被用作拒绝服务的攻击载体。由于 Web 服务器通常不会进行深层的请求检查，所以不可能在这个层面进行类似的检查。</p>
<p>另见 <a class="reference internal" href="#std:setting-FILE_UPLOAD_MAX_MEMORY_SIZE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FILE_UPLOAD_MAX_MEMORY_SIZE</span></code></a>。</p>
</div>
<div class="section" id="s-data-upload-max-number-fields">
<span id="s-std:setting-DATA_UPLOAD_MAX_NUMBER_FIELDS"></span><span id="data-upload-max-number-fields"></span><span id="std:setting-DATA_UPLOAD_MAX_NUMBER_FIELDS"></span><h3><code class="docutils literal notranslate"><span class="pre">DATA_UPLOAD_MAX_NUMBER_FIELDS</span></code><a class="headerlink" href="#data-upload-max-number-fields" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">1000</span></code></p>
<p>在发生 <a class="reference internal" href="exceptions.html#django.core.exceptions.SuspiciousOperation" title="django.core.exceptions.SuspiciousOperation"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SuspiciousOperation</span></code></a> （<code class="docutils literal notranslate"><span class="pre">TooManyFields</span></code>）之前，可以通过 GET 或 POST 接收到的参数的最大数量。你可以将其设置为 <code class="docutils literal notranslate"><span class="pre">None</span></code> 来禁用该检查。预计会收到异常多的表单字段的应用程序应该调整这个配置。</p>
<p>请求参数的数量与处理请求和填充 GET 和 POST 字典所需的时间有关。如果不加以检查，大的请求可能会被用作拒绝服务攻击的载体。由于 Web 服务器通常不会进行深层的请求检查，所以不可能在这个层面进行类似的检查。</p>
</div>
<div class="section" id="s-database-routers">
<span id="s-std:setting-DATABASE_ROUTERS"></span><span id="database-routers"></span><span id="std:setting-DATABASE_ROUTERS"></span><h3><code class="docutils literal notranslate"><span class="pre">DATABASE_ROUTERS</span></code><a class="headerlink" href="#database-routers" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>在执行数据库查询时，将用于确定使用哪个数据库的路由器列表。</p>
<p>参见 <a class="reference internal" href="../topics/db/multi-db.html#topics-db-multi-db-routing"><span class="std std-ref">多数据库配置中的自动数据库路由</span></a> 的文档。</p>
</div>
<div class="section" id="s-date-format">
<span id="s-std:setting-DATE_FORMAT"></span><span id="date-format"></span><span id="std:setting-DATE_FORMAT"></span><h3><code class="docutils literal notranslate"><span class="pre">DATE_FORMAT</span></code><a class="headerlink" href="#date-format" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'N</span> <span class="pre">j,</span> <span class="pre">Y'</span></code> （例如 <code class="docutils literal notranslate"><span class="pre">Feb.</span> <span class="pre">4,</span> <span class="pre">2003</span></code>）</p>
<p>在系统的任何部分显示日期字段时使用的默认格式。请注意，如果 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 被设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，那么本地决定的格式具有更高的优先权，并将被应用。参见 <a class="reference internal" href="templates/builtins.html#std:templatefilter-date"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">允许的日期格式字符串</span></code></a>。</p>
<p>另见 <a class="reference internal" href="#std:setting-DATETIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATETIME_FORMAT</span></code></a>、<a class="reference internal" href="#std:setting-TIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_FORMAT</span></code></a> 和 <a class="reference internal" href="#std:setting-SHORT_DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SHORT_DATE_FORMAT</span></code></a>。</p>
</div>
<div class="section" id="s-date-input-formats">
<span id="s-std:setting-DATE_INPUT_FORMATS"></span><span id="date-input-formats"></span><span id="std:setting-DATE_INPUT_FORMATS"></span><h3><code class="docutils literal notranslate"><span class="pre">DATE_INPUT_FORMATS</span></code><a class="headerlink" href="#date-input-formats" title="永久链接至标题">¶</a></h3>
<p>默认：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
    <span class="s1">&#39;%Y-%m-</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">,</span> <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%Y&#39;</span><span class="p">,</span> <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%y&#39;</span><span class="p">,</span> <span class="c1"># &#39;2006-10-25&#39;, &#39;10/25/2006&#39;, &#39;10/25/06&#39;</span>
    <span class="s1">&#39;%b </span><span class="si">%d</span><span class="s1"> %Y&#39;</span><span class="p">,</span> <span class="s1">&#39;%b </span><span class="si">%d</span><span class="s1">, %Y&#39;</span><span class="p">,</span>            <span class="c1"># &#39;Oct 25 2006&#39;, &#39;Oct 25, 2006&#39;</span>
    <span class="s1">&#39;</span><span class="si">%d</span><span class="s1"> %b %Y&#39;</span><span class="p">,</span> <span class="s1">&#39;</span><span class="si">%d</span><span class="s1"> %b, %Y&#39;</span><span class="p">,</span>            <span class="c1"># &#39;25 Oct 2006&#39;, &#39;25 Oct, 2006&#39;</span>
    <span class="s1">&#39;%B </span><span class="si">%d</span><span class="s1"> %Y&#39;</span><span class="p">,</span> <span class="s1">&#39;%B </span><span class="si">%d</span><span class="s1">, %Y&#39;</span><span class="p">,</span>            <span class="c1"># &#39;October 25 2006&#39;, &#39;October 25, 2006&#39;</span>
    <span class="s1">&#39;</span><span class="si">%d</span><span class="s1"> %B %Y&#39;</span><span class="p">,</span> <span class="s1">&#39;</span><span class="si">%d</span><span class="s1"> %B, %Y&#39;</span><span class="p">,</span>            <span class="c1"># &#39;25 October 2006&#39;, &#39;25 October, 2006&#39;</span>
<span class="p">]</span>
</pre></div>
</div>
<p>在日期字段上输入数据时接受的格式列表。格式将按顺序被尝试，使用第一个有效的格式。注意这些格式字符串使用 Python 的 <a class="reference external" href="https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior" title="(在 Python v3.10)"><span class="xref std std-ref">datetime 模块语法</span></a>，而不是来自 <a class="reference internal" href="templates/builtins.html#std:templatefilter-date"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">date</span></code></a> 模板过滤器的格式字符串。</p>
<p>当 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 时，将采用本地规定的格式，具有更高的优先权。</p>
<p>另见 <a class="reference internal" href="#std:setting-DATETIME_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATETIME_INPUT_FORMATS</span></code></a> 和 <a class="reference internal" href="#std:setting-TIME_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_INPUT_FORMATS</span></code></a>。</p>
</div>
<div class="section" id="s-datetime-format">
<span id="s-std:setting-DATETIME_FORMAT"></span><span id="datetime-format"></span><span id="std:setting-DATETIME_FORMAT"></span><h3><code class="docutils literal notranslate"><span class="pre">DATETIME_FORMAT</span></code><a class="headerlink" href="#datetime-format" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'N</span> <span class="pre">j,</span> <span class="pre">Y,</span> <span class="pre">P'</span></code> （例如 <code class="docutils literal notranslate"><span class="pre">Feb.</span> <span class="pre">4,</span> <span class="pre">2003,</span> <span class="pre">4</span> <span class="pre">p.m.</span></code>）</p>
<p>在系统的任何部分显示日期时间字段时使用的默认格式。请注意，如果 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 被设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，那么本地决定的格式具有更高的优先权，并将被应用。参见 <a class="reference internal" href="templates/builtins.html#std:templatefilter-date"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">允许的日期格式字符串</span></code></a>。</p>
<p>另见 <a class="reference internal" href="#std:setting-DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_FORMAT</span></code></a>、<a class="reference internal" href="#std:setting-TIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_FORMAT</span></code></a> 和 <a class="reference internal" href="#std:setting-SHORT_DATETIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SHORT_DATETIME_FORMAT</span></code></a>。</p>
</div>
<div class="section" id="s-datetime-input-formats">
<span id="s-std:setting-DATETIME_INPUT_FORMATS"></span><span id="datetime-input-formats"></span><span id="std:setting-DATETIME_INPUT_FORMATS"></span><h3><code class="docutils literal notranslate"><span class="pre">DATETIME_INPUT_FORMATS</span></code><a class="headerlink" href="#datetime-input-formats" title="永久链接至标题">¶</a></h3>
<p>默认：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
    <span class="s1">&#39;%Y-%m-</span><span class="si">%d</span><span class="s1"> %H:%M:%S&#39;</span><span class="p">,</span>     <span class="c1"># &#39;2006-10-25 14:30:59&#39;</span>
    <span class="s1">&#39;%Y-%m-</span><span class="si">%d</span><span class="s1"> %H:%M:%S.</span><span class="si">%f</span><span class="s1">&#39;</span><span class="p">,</span>  <span class="c1"># &#39;2006-10-25 14:30:59.000200&#39;</span>
    <span class="s1">&#39;%Y-%m-</span><span class="si">%d</span><span class="s1"> %H:%M&#39;</span><span class="p">,</span>        <span class="c1"># &#39;2006-10-25 14:30&#39;</span>
    <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%Y %H:%M:%S&#39;</span><span class="p">,</span>     <span class="c1"># &#39;10/25/2006 14:30:59&#39;</span>
    <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%Y %H:%M:%S.</span><span class="si">%f</span><span class="s1">&#39;</span><span class="p">,</span>  <span class="c1"># &#39;10/25/2006 14:30:59.000200&#39;</span>
    <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%Y %H:%M&#39;</span><span class="p">,</span>        <span class="c1"># &#39;10/25/2006 14:30&#39;</span>
    <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%y %H:%M:%S&#39;</span><span class="p">,</span>     <span class="c1"># &#39;10/25/06 14:30:59&#39;</span>
    <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%y %H:%M:%S.</span><span class="si">%f</span><span class="s1">&#39;</span><span class="p">,</span>  <span class="c1"># &#39;10/25/06 14:30:59.000200&#39;</span>
    <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%y %H:%M&#39;</span><span class="p">,</span>        <span class="c1"># &#39;10/25/06 14:30&#39;</span>
<span class="p">]</span>
</pre></div>
</div>
<p>在日期时间字段上输入数据时可接受的格式列表。格式将按顺序被尝试，使用第一个有效的格式。注意这些格式字符串使用 Python 的 <a class="reference external" href="https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior" title="(在 Python v3.10)"><span class="xref std std-ref">datetime 模块语法</span></a>，而不是 <a class="reference internal" href="templates/builtins.html#std:templatefilter-date"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">date</span></code></a> 模板过滤器的格式字符串。纯日期格式不包括在内，因为日期时间字段会在最后时刻自动尝试 <a class="reference internal" href="#std:setting-DATE_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_INPUT_FORMATS</span></code></a>。</p>
<p>当 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 时，将采用本地规定的格式，具有更高的优先权。</p>
<p>另见 <a class="reference internal" href="#std:setting-DATE_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_INPUT_FORMATS</span></code></a> 和 <a class="reference internal" href="#std:setting-TIME_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_INPUT_FORMATS</span></code></a>。</p>
<div class="versionchanged">
<span class="title">Changed in Django 3.1:</span> <p>在旧版本中，默认的是一个包含仅有日期的格式的列表。</p>
</div>
</div>
<div class="section" id="s-debug">
<span id="s-std:setting-DEBUG"></span><span id="debug"></span><span id="std:setting-DEBUG"></span><h3><code class="docutils literal notranslate"><span class="pre">DEBUG</span></code><a class="headerlink" href="#debug" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>一个开启、关闭调试模式的布尔值。</p>
<p>永远不要在 <a class="reference internal" href="#std:setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG</span></code></a> 开启的情况下将网站部署到生产中。</p>
<p>调试模式的主要功能之一是显示详细的错误页面。如果你的应用程序在 <a class="reference internal" href="#std:setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 时引发了异常，Django 会显示一个详细的回溯，包括很多关于你的环境的元数据，比如所有当前定义的 Django 配置（来自 <code class="docutils literal notranslate"><span class="pre">settings.py</span></code>）。</p>
<p>作为一项安全措施，Django将 <em>不</em> 包含可能是敏感的配置，如 <a class="reference internal" href="#std:setting-SECRET_KEY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECRET_KEY</span></code></a>。具体来说，它将排除任何名称中包含以下内容的配置。</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">'API'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'KEY'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'PASS'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'SECRET'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'SIGNATURE'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'TOKEN'</span></code></li>
</ul>
<p>请注意，这些是 <em>部分</em> 匹配。<code class="docutils literal notranslate"><span class="pre">'PASS'</span></code> 也将与 PASSWORD 匹配，正如 <code class="docutils literal notranslate"><span class="pre">'TOKEN'</span></code> 也将与 TOKENIZED 匹配，以此类推。</p>
<p>不过，请注意，你的调试输出中总会有一些部分是不适合公开的。文件路径、配置选项等都会给攻击者提供关于你的服务器的额外信息。</p>
<p>同样重要的是，当 <a class="reference internal" href="#std:setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG</span></code></a> 开启时，Django 会记住它执行的每个 SQL 查询。这在调试时很有用，但在生产服务器上会迅速消耗内存。</p>
<p>最后，如果 <a class="reference internal" href="#std:setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code>，还需要正确设置 <a class="reference internal" href="#std:setting-ALLOWED_HOSTS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">ALLOWED_HOSTS</span></code></a> 配置。否则，所有的请求都会以 “Bad Request (400) ” 返回。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">默认的 <code class="file docutils literal notranslate"><span class="pre">settings.py</span></code> 文件由 <a class="reference internal" href="django-admin.html#django-admin-startproject"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">django-admin</span> <span class="pre">startproject</span></code></a> 创建，为了方便，设置 <code class="docutils literal notranslate"><span class="pre">DEBUG</span> <span class="pre">=</span> <span class="pre">True</span></code>。</p>
</div>
</div>
<div class="section" id="s-debug-propagate-exceptions">
<span id="s-std:setting-DEBUG_PROPAGATE_EXCEPTIONS"></span><span id="debug-propagate-exceptions"></span><span id="std:setting-DEBUG_PROPAGATE_EXCEPTIONS"></span><h3><code class="docutils literal notranslate"><span class="pre">DEBUG_PROPAGATE_EXCEPTIONS</span></code><a class="headerlink" href="#debug-propagate-exceptions" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>如果设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，Django 对视图函数的异常处理（<a class="reference internal" href="urls.html#django.conf.urls.handler500" title="django.conf.urls.handler500"><code class="xref py py-data docutils literal notranslate"><span class="pre">handler500</span></code></a>，或调试视图，如果 <a class="reference internal" href="#std:setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code>）和 Django 对 500 响应的记录（<a class="reference internal" href="../topics/logging.html#django-request-logger"><span class="std std-ref">django.request</span></a>）将被跳过，异常向上传播。</p>
<p>这对于一些测试配置是有用的。除非你想让你的 web 服务器（而不是 Django）生成“内部服务器错误”的响应，否则它不应该被用于实时站点。在这种情况下，确保你的服务器不会在响应中显示堆栈跟踪或其他敏感信息。</p>
</div>
<div class="section" id="s-decimal-separator">
<span id="s-std:setting-DECIMAL_SEPARATOR"></span><span id="decimal-separator"></span><span id="std:setting-DECIMAL_SEPARATOR"></span><h3><code class="docutils literal notranslate"><span class="pre">DECIMAL_SEPARATOR</span></code><a class="headerlink" href="#decimal-separator" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'.'</span></code> （点）</p>
<p>格式化小数时使用的默认小数分隔符。</p>
<p>请注意，如果 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，那么将采用本地决定的格式，具有更高的优先权。</p>
<p>另见 <a class="reference internal" href="#std:setting-NUMBER_GROUPING"><code class="xref std std-setting docutils literal notranslate"><span class="pre">NUMBER_GROUPING</span></code></a>、<a class="reference internal" href="#std:setting-THOUSAND_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">THOUSAND_SEPARATOR</span></code></a> 和 <a class="reference internal" href="#std:setting-USE_THOUSAND_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_THOUSAND_SEPARATOR</span></code></a>。</p>
</div>
<div class="section" id="s-default-auto-field">
<span id="s-std:setting-DEFAULT_AUTO_FIELD"></span><span id="default-auto-field"></span><span id="std:setting-DEFAULT_AUTO_FIELD"></span><h3><code class="docutils literal notranslate"><span class="pre">DEFAULT_AUTO_FIELD</span></code><a class="headerlink" href="#default-auto-field" title="永久链接至标题">¶</a></h3>
<div class="versionadded">
<span class="title">New in Django 3.2.</span> </div>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'</span></code><a class="reference internal" href="models/fields.html#django.db.models.AutoField" title="django.db.models.AutoField"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.db.models.AutoField</span></code></a><code class="docutils literal notranslate"><span class="pre">'</span></code></p>
<p>默认的主键字段类型，用于没有带有 <a class="reference internal" href="models/fields.html#django.db.models.Field.primary_key" title="django.db.models.Field.primary_key"><code class="xref py py-attr docutils literal notranslate"><span class="pre">primary_key=True</span></code></a> 字段的模型。</p>
<div class="admonition-migrating-auto-created-through-tables admonition">
<p class="first admonition-title">迁移自动创建的中间表</p>
<p>当为多对多关系创建新的自动创建的中间表时，将尊重 <code class="docutils literal notranslate"><span class="pre">DEFAULT_AUTO_FIELD</span></code> 的值。</p>
<p>不幸的是，现有的自动创建的中间表的主键目前不能被迁移框架所更新。</p>
<p>这意味着，如果你切换了 <code class="docutils literal notranslate"><span class="pre">DEFAULT_AUTO_FIELD</span></code> 的值，然后生成迁移，相关模型的主键将被更新，来自中间表的外键也将被更新，但是自动创建的中间表的主键将不会被迁移。</p>
<p>为了解决这个问题，你应该在你的迁移中添加一个 <a class="reference internal" href="migration-operations.html#django.db.migrations.operations.RunSQL" title="django.db.migrations.operations.RunSQL"><code class="xref py py-class docutils literal notranslate"><span class="pre">RunSQL</span></code></a> 操作来执行所需的 <code class="docutils literal notranslate"><span class="pre">ALTER</span> <span class="pre">TABLE</span></code> 步骤。你可以通过 <code class="docutils literal notranslate"><span class="pre">sqlmigrate</span></code>、<code class="docutils literal notranslate"><span class="pre">dbshell</span></code> 或字段的 <code class="docutils literal notranslate"><span class="pre">remote_field.through._meta.db_table</span></code> 属性来检查现有的表名。</p>
<p>通过模型明确定义的，已经由迁移系统处理。</p>
<p class="last">允许对现有的自动创建的中间表的主键进行自动迁移 <a class="reference external" href="https://code.djangoproject.com/ticket/32674">可能会在以后实现</a>。</p>
</div>
</div>
<div class="section" id="s-default-charset">
<span id="s-std:setting-DEFAULT_CHARSET"></span><span id="default-charset"></span><span id="std:setting-DEFAULT_CHARSET"></span><h3><code class="docutils literal notranslate"><span class="pre">DEFAULT_CHARSET</span></code><a class="headerlink" href="#default-charset" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'utf-8'</span></code></p>
<p>如果没有手动指定 MIME 类型，所有 <code class="docutils literal notranslate"><span class="pre">HttpResponse</span></code> 对象将使用默认字符集。在构建 <code class="docutils literal notranslate"><span class="pre">Content-Type</span></code> 头时使用。</p>
</div>
<div class="section" id="s-default-exception-reporter">
<span id="s-std:setting-DEFAULT_EXCEPTION_REPORTER"></span><span id="default-exception-reporter"></span><span id="std:setting-DEFAULT_EXCEPTION_REPORTER"></span><h3><code class="docutils literal notranslate"><span class="pre">DEFAULT_EXCEPTION_REPORTER</span></code><a class="headerlink" href="#default-exception-reporter" title="永久链接至标题">¶</a></h3>
<div class="versionadded">
<span class="title">New in Django 3.1.</span> </div>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'</span></code><a class="reference internal" href="../howto/error-reporting.html#django.views.debug.ExceptionReporter" title="django.views.debug.ExceptionReporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.debug.ExceptionReporter</span></code></a><code class="docutils literal notranslate"><span class="pre">'</span></code></p>
<p>如果还没有为 <a class="reference internal" href="request-response.html#django.http.HttpRequest" title="django.http.HttpRequest"><code class="xref py py-class docutils literal notranslate"><span class="pre">HttpRequest</span></code></a> 实例分配任何异常报告类，则使用默认的异常报告类。参见 <a class="reference internal" href="../howto/error-reporting.html#custom-error-reports"><span class="std std-ref">自定义错误报告</span></a>。</p>
</div>
<div class="section" id="s-default-exception-reporter-filter">
<span id="s-std:setting-DEFAULT_EXCEPTION_REPORTER_FILTER"></span><span id="default-exception-reporter-filter"></span><span id="std:setting-DEFAULT_EXCEPTION_REPORTER_FILTER"></span><h3><code class="docutils literal notranslate"><span class="pre">DEFAULT_EXCEPTION_REPORTER_FILTER</span></code><a class="headerlink" href="#default-exception-reporter-filter" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'</span></code><a class="reference internal" href="../howto/error-reporting.html#django.views.debug.SafeExceptionReporterFilter" title="django.views.debug.SafeExceptionReporterFilter"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.debug.SafeExceptionReporterFilter</span></code></a><code class="docutils literal notranslate"><span class="pre">'</span></code></p>
<p>如果还没有为 <a class="reference internal" href="request-response.html#django.http.HttpRequest" title="django.http.HttpRequest"><code class="xref py py-class docutils literal notranslate"><span class="pre">HttpRequest</span></code></a> 实例分配任何异常报告过滤类，则使用默认的异常报告过滤类。参见 <a class="reference internal" href="../howto/error-reporting.html#filtering-error-reports"><span class="std std-ref">过滤错误报告</span></a>。</p>
</div>
<div class="section" id="s-default-file-storage">
<span id="s-std:setting-DEFAULT_FILE_STORAGE"></span><span id="default-file-storage"></span><span id="std:setting-DEFAULT_FILE_STORAGE"></span><h3><code class="docutils literal notranslate"><span class="pre">DEFAULT_FILE_STORAGE</span></code><a class="headerlink" href="#default-file-storage" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'</span></code><a class="reference internal" href="files/storage.html#django.core.files.storage.FileSystemStorage" title="django.core.files.storage.FileSystemStorage"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.core.files.storage.FileSystemStorage</span></code></a><code class="docutils literal notranslate"><span class="pre">'</span></code></p>
<p>默认的文件存储类，用于任何与文件相关的操作，不指定特定的存储系统。参见 <a class="reference internal" href="../topics/files.html"><span class="doc">管理文件</span></a>。</p>
</div>
<div class="section" id="s-default-from-email">
<span id="s-std:setting-DEFAULT_FROM_EMAIL"></span><span id="default-from-email"></span><span id="std:setting-DEFAULT_FROM_EMAIL"></span><h3><code class="docutils literal notranslate"><span class="pre">DEFAULT_FROM_EMAIL</span></code><a class="headerlink" href="#default-from-email" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'webmaster&#64;localhost'</span></code></p>
<p>默认电子邮件地址，用于网站管理员的各种自动通信。这不包括发送到 <a class="reference internal" href="#std:setting-ADMINS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">ADMINS</span></code></a> 和 <a class="reference internal" href="#std:setting-MANAGERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MANAGERS</span></code></a> 的错误信息；关于这一点，请参见 <a class="reference internal" href="#std:setting-SERVER_EMAIL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SERVER_EMAIL</span></code></a>。</p>
</div>
<div class="section" id="s-default-hashing-algorithm">
<span id="s-std:setting-DEFAULT_HASHING_ALGORITHM"></span><span id="default-hashing-algorithm"></span><span id="std:setting-DEFAULT_HASHING_ALGORITHM"></span><h3><code class="docutils literal notranslate"><span class="pre">DEFAULT_HASHING_ALGORITHM</span></code><a class="headerlink" href="#default-hashing-algorithm" title="永久链接至标题">¶</a></h3>
<div class="versionadded">
<span class="title">New in Django 3.1.</span> </div>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'sha256'</span></code></p>
<p>默认的散列算法，用于对 cookie、管理员站点中的密码重置令牌、用户会话以及 <a class="reference internal" href="../topics/signing.html#django.core.signing.Signer" title="django.core.signing.Signer"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.core.signing.Signer</span></code></a> 和 <a class="reference internal" href="../topics/signing.html#django.core.signing.dumps" title="django.core.signing.dumps"><code class="xref py py-meth docutils literal notranslate"><span class="pre">django.core.signing.dumps()</span></code></a> 创建的签名进行编码。算法必须是 <code class="docutils literal notranslate"><span class="pre">'sha1'</span></code> 或 <code class="docutils literal notranslate"><span class="pre">'sha256'</span></code>。详细使用方法请参见 <a class="reference internal" href="../releases/3.1.html#default-hashing-algorithm-usage"><span class="std std-ref">发行说明</span></a>。</p>
<div class="deprecated">
<p><span class="versionmodified">3.1 版后已移除: </span>这个过渡性设置已经被废弃。它和使用 SHA-1 散列算法的 tokens、cookie、session 和签名的支持将在 Django 4.0 中被移除。</p>
</div>
</div>
<div class="section" id="s-default-index-tablespace">
<span id="s-std:setting-DEFAULT_INDEX_TABLESPACE"></span><span id="default-index-tablespace"></span><span id="std:setting-DEFAULT_INDEX_TABLESPACE"></span><h3><code class="docutils literal notranslate"><span class="pre">DEFAULT_INDEX_TABLESPACE</span></code><a class="headerlink" href="#default-index-tablespace" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>如果后端支持的话，在没有指定索引的字段上使用的默认表空间（参见 <a class="reference internal" href="../topics/db/tablespaces.html"><span class="doc">表空间（Tablespaces）</span></a>）。</p>
</div>
<div class="section" id="s-default-tablespace">
<span id="s-std:setting-DEFAULT_TABLESPACE"></span><span id="default-tablespace"></span><span id="std:setting-DEFAULT_TABLESPACE"></span><h3><code class="docutils literal notranslate"><span class="pre">DEFAULT_TABLESPACE</span></code><a class="headerlink" href="#default-tablespace" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>对于没有指定表空间的模型，如果后端支持，则使用默认表空间（参见 <a class="reference internal" href="../topics/db/tablespaces.html"><span class="doc">表空间（Tablespaces）</span></a>）。</p>
</div>
<div class="section" id="s-disallowed-user-agents">
<span id="s-std:setting-DISALLOWED_USER_AGENTS"></span><span id="disallowed-user-agents"></span><span id="std:setting-DISALLOWED_USER_AGENTS"></span><h3><code class="docutils literal notranslate"><span class="pre">DISALLOWED_USER_AGENTS</span></code><a class="headerlink" href="#disallowed-user-agents" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>编译后的正则表达式对象列表，代表全系统范围内不允许访问任何页面的 User-Agent 字符串。用于机器人／爬虫。只有在安装了 <code class="docutils literal notranslate"><span class="pre">CommonMiddleware</span></code> 的情况下才会使用（参见 <a class="reference internal" href="../topics/http/middleware.html"><span class="doc">中间件</span></a>）。</p>
</div>
<div class="section" id="s-email-backend">
<span id="s-std:setting-EMAIL_BACKEND"></span><span id="email-backend"></span><span id="std:setting-EMAIL_BACKEND"></span><h3><code class="docutils literal notranslate"><span class="pre">EMAIL_BACKEND</span></code><a class="headerlink" href="#email-backend" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'</span></code><a class="reference internal" href="../topics/email.html#django.core.mail.backends.smtp.EmailBackend" title="django.core.mail.backends.smtp.EmailBackend"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.core.mail.backends.smtp.EmailBackend</span></code></a><code class="docutils literal notranslate"><span class="pre">'</span></code></p>
<p>用于发送邮件的后端。关于可用的后端列表，请参见 <a class="reference internal" href="../topics/email.html"><span class="doc">发送邮件</span></a>。</p>
</div>
<div class="section" id="s-email-file-path">
<span id="s-std:setting-EMAIL_FILE_PATH"></span><span id="email-file-path"></span><span id="std:setting-EMAIL_FILE_PATH"></span><h3><code class="docutils literal notranslate"><span class="pre">EMAIL_FILE_PATH</span></code><a class="headerlink" href="#email-file-path" title="永久链接至标题">¶</a></h3>
<p>默认：未定义</p>
<p><a class="reference internal" href="../topics/email.html#topic-email-file-backend"><span class="std std-ref">文件邮件后端</span></a> 用来存储输出文件的目录。</p>
<div class="versionchanged">
<span class="title">Changed in Django 3.1:</span> <p>已添加对 <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.10)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> 的支持。</p>
</div>
</div>
<div class="section" id="s-email-host">
<span id="s-std:setting-EMAIL_HOST"></span><span id="email-host"></span><span id="std:setting-EMAIL_HOST"></span><h3><code class="docutils literal notranslate"><span class="pre">EMAIL_HOST</span></code><a class="headerlink" href="#email-host" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'localhost'</span></code></p>
<p>用于发送电子邮件的主机。</p>
<p>另见 <a class="reference internal" href="#std:setting-EMAIL_PORT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_PORT</span></code></a>。</p>
</div>
<div class="section" id="s-email-host-password">
<span id="s-std:setting-EMAIL_HOST_PASSWORD"></span><span id="email-host-password"></span><span id="std:setting-EMAIL_HOST_PASSWORD"></span><h3><code class="docutils literal notranslate"><span class="pre">EMAIL_HOST_PASSWORD</span></code><a class="headerlink" href="#email-host-password" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>在 <a class="reference internal" href="#std:setting-EMAIL_HOST"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_HOST</span></code></a> 中定义的 SMTP 服务器使用的密码。这个配置和 <a class="reference internal" href="#std:setting-EMAIL_HOST_USER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_HOST_USER</span></code></a> 中的密码一起使用。如果这两个配置中的任何一个为空，Django 就不会尝试验证。</p>
<p>另见 <a class="reference internal" href="#std:setting-EMAIL_HOST_USER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_HOST_USER</span></code></a>。</p>
</div>
<div class="section" id="s-email-host-user">
<span id="s-std:setting-EMAIL_HOST_USER"></span><span id="email-host-user"></span><span id="std:setting-EMAIL_HOST_USER"></span><h3><code class="docutils literal notranslate"><span class="pre">EMAIL_HOST_USER</span></code><a class="headerlink" href="#email-host-user" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>在 <a class="reference internal" href="#std:setting-EMAIL_HOST"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_HOST</span></code></a> 中定义的 SMTP 服务器的用户名。如果为空，Django 将不会尝试认证。</p>
<p>另见 <a class="reference internal" href="#std:setting-EMAIL_HOST_PASSWORD"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_HOST_PASSWORD</span></code></a>。</p>
</div>
<div class="section" id="s-email-port">
<span id="s-std:setting-EMAIL_PORT"></span><span id="email-port"></span><span id="std:setting-EMAIL_PORT"></span><h3><code class="docutils literal notranslate"><span class="pre">EMAIL_PORT</span></code><a class="headerlink" href="#email-port" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">25</span></code></p>
<p>在 :setting:<a href="#id1"><span class="problematic" id="id2">`</span></a>EMAIL_HOST' 中定义的 SMTP 服务器使用的端口。</p>
</div>
<div class="section" id="s-email-subject-prefix">
<span id="s-std:setting-EMAIL_SUBJECT_PREFIX"></span><span id="email-subject-prefix"></span><span id="std:setting-EMAIL_SUBJECT_PREFIX"></span><h3><code class="docutils literal notranslate"><span class="pre">EMAIL_SUBJECT_PREFIX</span></code><a class="headerlink" href="#email-subject-prefix" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'[Django]</span> <span class="pre">'</span></code></p>
<p>用 <code class="docutils literal notranslate"><span class="pre">django.core.mail.mail_admins</span></code> 或 <code class="docutils literal notranslate"><span class="pre">django.core.mail.mail_managers</span></code> 发送邮件的主题行前缀。你可能会想要包含尾部的空格。</p>
</div>
<div class="section" id="s-email-use-localtime">
<span id="s-std:setting-EMAIL_USE_LOCALTIME"></span><span id="email-use-localtime"></span><span id="std:setting-EMAIL_USE_LOCALTIME"></span><h3><code class="docutils literal notranslate"><span class="pre">EMAIL_USE_LOCALTIME</span></code><a class="headerlink" href="#email-use-localtime" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>是否以当地时区（<code class="docutils literal notranslate"><span class="pre">True</span></code>）或 UTC（<code class="docutils literal notranslate"><span class="pre">False</span></code>）发送 SMTP <code class="docutils literal notranslate"><span class="pre">Date</span></code> 邮件头。</p>
</div>
<div class="section" id="s-email-use-tls">
<span id="s-std:setting-EMAIL_USE_TLS"></span><span id="email-use-tls"></span><span id="std:setting-EMAIL_USE_TLS"></span><h3><code class="docutils literal notranslate"><span class="pre">EMAIL_USE_TLS</span></code><a class="headerlink" href="#email-use-tls" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>与 SMTP 服务器对话时是否使用 TLS（安全）连接。这用于显式 TLS 连接，一般在 587 端口。如果你遇到挂起的连接，请查看隐式 TLS 配置 <a class="reference internal" href="#std:setting-EMAIL_USE_SSL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_USE_SSL</span></code></a>。</p>
</div>
<div class="section" id="s-email-use-ssl">
<span id="s-std:setting-EMAIL_USE_SSL"></span><span id="email-use-ssl"></span><span id="std:setting-EMAIL_USE_SSL"></span><h3><code class="docutils literal notranslate"><span class="pre">EMAIL_USE_SSL</span></code><a class="headerlink" href="#email-use-ssl" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>与 SMTP 服务器对话时是否使用隐式 TLS（安全）连接。在大多数电子邮件文档中，这种类型的 TLS 连接被称为 SSL。它通常在 465 端口使用。如果你遇到问题，请查看显式 TLS 配置 <a class="reference internal" href="#std:setting-EMAIL_USE_TLS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_USE_TLS</span></code></a>。</p>
<p>注意 <a class="reference internal" href="#std:setting-EMAIL_USE_TLS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_USE_TLS</span></code></a> ／ <a class="reference internal" href="#std:setting-EMAIL_USE_SSL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_USE_SSL</span></code></a> 是相互排斥的，所以只能将其中一个设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>。</p>
</div>
<div class="section" id="s-email-ssl-certfile">
<span id="s-std:setting-EMAIL_SSL_CERTFILE"></span><span id="email-ssl-certfile"></span><span id="std:setting-EMAIL_SSL_CERTFILE"></span><h3><code class="docutils literal notranslate"><span class="pre">EMAIL_SSL_CERTFILE</span></code><a class="headerlink" href="#email-ssl-certfile" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>如果 <a class="reference internal" href="#std:setting-EMAIL_USE_SSL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_USE_SSL</span></code></a> 或 <a class="reference internal" href="#std:setting-EMAIL_USE_TLS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_USE_TLS</span></code></a> 是 <code class="docutils literal notranslate"><span class="pre">True</span></code>，你可以选择指定一个 PEM 格式的证书链文件的路径，用于 SSL 连接。</p>
</div>
<div class="section" id="s-email-ssl-keyfile">
<span id="s-std:setting-EMAIL_SSL_KEYFILE"></span><span id="email-ssl-keyfile"></span><span id="std:setting-EMAIL_SSL_KEYFILE"></span><h3><code class="docutils literal notranslate"><span class="pre">EMAIL_SSL_KEYFILE</span></code><a class="headerlink" href="#email-ssl-keyfile" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>如果 <a class="reference internal" href="#std:setting-EMAIL_USE_SSL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_USE_SSL</span></code></a> 或 <a class="reference internal" href="#std:setting-EMAIL_USE_TLS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_USE_TLS</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，你可以选择性地指定用于 SSL 连接的 PEM 格式化私钥文件的路径。</p>
<p>请注意，设置 <a class="reference internal" href="#std:setting-EMAIL_SSL_CERTFILE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_SSL_CERTFILE</span></code></a> 和 <a class="reference internal" href="#std:setting-EMAIL_SSL_KEYFILE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_SSL_KEYFILE</span></code></a> 不会导致任何证书检查。它们被传递给底层的 SSL 连接。请参考 Python 的 <a class="reference external" href="https://docs.python.org/3/library/ssl.html#ssl.wrap_socket" title="(在 Python v3.10)"><code class="docutils literal notranslate"><span class="pre">ssl.wrap_socket()</span></code></a> 函数的文档，了解如何处理证书链文件和私钥文件。</p>
</div>
<div class="section" id="s-email-timeout">
<span id="s-std:setting-EMAIL_TIMEOUT"></span><span id="email-timeout"></span><span id="std:setting-EMAIL_TIMEOUT"></span><h3><code class="docutils literal notranslate"><span class="pre">EMAIL_TIMEOUT</span></code><a class="headerlink" href="#email-timeout" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>指定阻止连接尝试等操作的超时时间，以秒为单位。</p>
</div>
<div class="section" id="s-file-upload-handlers">
<span id="s-std:setting-FILE_UPLOAD_HANDLERS"></span><span id="file-upload-handlers"></span><span id="std:setting-FILE_UPLOAD_HANDLERS"></span><h3><code class="docutils literal notranslate"><span class="pre">FILE_UPLOAD_HANDLERS</span></code><a class="headerlink" href="#file-upload-handlers" title="永久链接至标题">¶</a></h3>
<p>默认：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
    <span class="s1">&#39;django.core.files.uploadhandler.MemoryFileUploadHandler&#39;</span><span class="p">,</span>
    <span class="s1">&#39;django.core.files.uploadhandler.TemporaryFileUploadHandler&#39;</span><span class="p">,</span>
<span class="p">]</span>
</pre></div>
</div>
<p>上传过程中使用的处理程序列表。改变这个配置可以完全自定义——甚至替换——Django 的上传过程。</p>
<p>详情参见 <a class="reference internal" href="../topics/files.html"><span class="doc">管理文件</span></a>。</p>
</div>
<div class="section" id="s-file-upload-max-memory-size">
<span id="s-std:setting-FILE_UPLOAD_MAX_MEMORY_SIZE"></span><span id="file-upload-max-memory-size"></span><span id="std:setting-FILE_UPLOAD_MAX_MEMORY_SIZE"></span><h3><code class="docutils literal notranslate"><span class="pre">FILE_UPLOAD_MAX_MEMORY_SIZE</span></code><a class="headerlink" href="#file-upload-max-memory-size" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">2621440</span></code> （即 2.5 MB）。</p>
<p>上传的文件在被传送到文件系统之前的最大尺寸（以字节为单位）。详见 <a class="reference internal" href="../topics/files.html"><span class="doc">管理文件</span></a>。</p>
<p>另见 <a class="reference internal" href="#std:setting-DATA_UPLOAD_MAX_MEMORY_SIZE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATA_UPLOAD_MAX_MEMORY_SIZE</span></code></a>。</p>
</div>
<div class="section" id="s-file-upload-directory-permissions">
<span id="s-std:setting-FILE_UPLOAD_DIRECTORY_PERMISSIONS"></span><span id="file-upload-directory-permissions"></span><span id="std:setting-FILE_UPLOAD_DIRECTORY_PERMISSIONS"></span><h3><code class="docutils literal notranslate"><span class="pre">FILE_UPLOAD_DIRECTORY_PERMISSIONS</span></code><a class="headerlink" href="#file-upload-directory-permissions" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>适用于上传文件过程中创建的目录的数字模式。</p>
<p>当使用 <a class="reference internal" href="contrib/staticfiles.html#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a> 管理命令时，这个配置也决定了收集的静态目录的默认权限。覆盖它的细节请参见 <a class="reference internal" href="contrib/staticfiles.html#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a>。</p>
<p>这个值反映了 <a class="reference internal" href="#std:setting-FILE_UPLOAD_PERMISSIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FILE_UPLOAD_PERMISSIONS</span></code></a> 配置的功能和注意事项。</p>
</div>
<div class="section" id="s-file-upload-permissions">
<span id="s-std:setting-FILE_UPLOAD_PERMISSIONS"></span><span id="file-upload-permissions"></span><span id="std:setting-FILE_UPLOAD_PERMISSIONS"></span><h3><code class="docutils literal notranslate"><span class="pre">FILE_UPLOAD_PERMISSIONS</span></code><a class="headerlink" href="#file-upload-permissions" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">0o644</span></code></p>
<p>设置新上传文件的数字模式（即 <code class="docutils literal notranslate"><span class="pre">0o644</span></code>）。关于这些模式的更多信息，请参见 <a class="reference external" href="https://docs.python.org/3/library/os.html#os.chmod" title="(在 Python v3.10)"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.chmod()</span></code></a> 的文档。</p>
<p>如果 <code class="docutils literal notranslate"><span class="pre">None</span></code>，你会得到操作系统依赖的行为。在大多数平台上，临时文件的模式为 <code class="docutils literal notranslate"><span class="pre">0o600</span></code>，从内存中保存的文件将使用系统的标准 umask 保存。</p>
<p>出于安全考虑，这些权限不应用于存储在 <a class="reference internal" href="#std:setting-FILE_UPLOAD_TEMP_DIR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FILE_UPLOAD_TEMP_DIR</span></code></a> 中的临时文件。</p>
<p>当使用 <a class="reference internal" href="contrib/staticfiles.html#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a> 管理命令时，这个配置也决定了收集的静态文件的默认权限。覆盖它的细节请参见 <a class="reference internal" href="contrib/staticfiles.html#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a>。</p>
<div class="admonition warning">
<p class="first admonition-title">警告</p>
<p><strong>总是在模式前加上 **`0o`</strong> 。**</p>
<p class="last">如果你不熟悉文件模式，请注意 <code class="docutils literal notranslate"><span class="pre">0o</span></code> 的前缀是非常重要的：它表示一个八进制数，这就是模式必须被指定的方式。如果你试图使用 <code class="docutils literal notranslate"><span class="pre">644</span></code>，你会得到完全错误的行为。</p>
</div>
</div>
<div class="section" id="s-file-upload-temp-dir">
<span id="s-std:setting-FILE_UPLOAD_TEMP_DIR"></span><span id="file-upload-temp-dir"></span><span id="std:setting-FILE_UPLOAD_TEMP_DIR"></span><h3><code class="docutils literal notranslate"><span class="pre">FILE_UPLOAD_TEMP_DIR</span></code><a class="headerlink" href="#file-upload-temp-dir" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>上传文件时要临时存储数据的目录（一般是大于 <a class="reference internal" href="#std:setting-FILE_UPLOAD_MAX_MEMORY_SIZE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FILE_UPLOAD_MAX_MEMORY_SIZE</span></code></a> 的文件）。如果 <code class="docutils literal notranslate"><span class="pre">None</span></code>，Django 将使用操作系统的标准临时目录。例如，在 <a href="#id1"><span class="problematic" id="id2">*</span></a>nix 风格的操作系统上，会默认为 <code class="docutils literal notranslate"><span class="pre">/tmp</span></code>。</p>
<p>详情参见 <a class="reference internal" href="../topics/files.html"><span class="doc">管理文件</span></a>。</p>
</div>
<div class="section" id="s-first-day-of-week">
<span id="s-std:setting-FIRST_DAY_OF_WEEK"></span><span id="first-day-of-week"></span><span id="std:setting-FIRST_DAY_OF_WEEK"></span><h3><code class="docutils literal notranslate"><span class="pre">FIRST_DAY_OF_WEEK</span></code><a class="headerlink" href="#first-day-of-week" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">0</span></code> （星期日）</p>
<p>代表一周第一天的数字。这在显示日历时特别有用。该值仅在不使用格式国际化时使用，或者当无法为当前语言环境找到格式时使用。</p>
<p>该值必须是 0 到 6 的整数，其中 0 代表周日，1 代表周一，以此类推。</p>
</div>
<div class="section" id="s-fixture-dirs">
<span id="s-std:setting-FIXTURE_DIRS"></span><span id="fixture-dirs"></span><span id="std:setting-FIXTURE_DIRS"></span><h3><code class="docutils literal notranslate"><span class="pre">FIXTURE_DIRS</span></code><a class="headerlink" href="#fixture-dirs" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>除了每个应用程序的 <code class="docutils literal notranslate"><span class="pre">fixtures</span></code> 目录外，按搜索顺序列出了搜索辅助工具文件的目录。</p>
<p>请注意，这些路径应该使用 Unix 风格的斜线，即使在 Windows 上也是如此。</p>
<p>参见 <a class="reference internal" href="../howto/initial-data.html#initial-data-via-fixtures"><span class="std std-ref">通过固定内容提供数据</span></a> 和 <a class="reference internal" href="../topics/testing/tools.html#topics-testing-fixtures"><span class="std std-ref">辅助工具加载</span></a>。</p>
</div>
<div class="section" id="s-force-script-name">
<span id="s-std:setting-FORCE_SCRIPT_NAME"></span><span id="force-script-name"></span><span id="std:setting-FORCE_SCRIPT_NAME"></span><h3><code class="docutils literal notranslate"><span class="pre">FORCE_SCRIPT_NAME</span></code><a class="headerlink" href="#force-script-name" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>如果不是 <code class="docutils literal notranslate"><span class="pre">None</span></code>，将作为任何 HTTP 请求中 <code class="docutils literal notranslate"><span class="pre">SCRIPT_NAME</span></code> 环境变量的值。这个设置可以用来覆盖服务器提供的 <code class="docutils literal notranslate"><span class="pre">SCRIPT_NAME</span></code> 的值，这个值可能是首选值的重写版本，也可能根本没有提供。它还被 <a class="reference internal" href="applications.html#django.setup" title="django.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.setup()</span></code></a> 用来在请求／响应周期之外设置 URL 解析器脚本前缀（例如在管理命令和独立脚本中），以便在 <code class="docutils literal notranslate"><span class="pre">SCRIPT_NAME</span></code> 不是 <code class="docutils literal notranslate"><span class="pre">/</span></code> 时生成正确的 URL。</p>
</div>
<div class="section" id="s-form-renderer">
<span id="s-std:setting-FORM_RENDERER"></span><span id="form-renderer"></span><span id="std:setting-FORM_RENDERER"></span><h3><code class="docutils literal notranslate"><span class="pre">FORM_RENDERER</span></code><a class="headerlink" href="#form-renderer" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'</span></code><a class="reference internal" href="forms/renderers.html#django.forms.renderers.DjangoTemplates" title="django.forms.renderers.DjangoTemplates"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.forms.renderers.DjangoTemplates</span></code></a><code class="docutils literal notranslate"><span class="pre">'</span></code></p>
<p>The class that renders form widgets. It must implement <a class="reference internal" href="forms/renderers.html#low-level-widget-render-api"><span class="std std-ref">the low-level
render API</span></a>. Included form renderers are:</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">'</span></code><a class="reference internal" href="forms/renderers.html#django.forms.renderers.DjangoTemplates" title="django.forms.renderers.DjangoTemplates"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.forms.renderers.DjangoTemplates</span></code></a><code class="docutils literal notranslate"><span class="pre">'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'</span></code><a class="reference internal" href="forms/renderers.html#django.forms.renderers.Jinja2" title="django.forms.renderers.Jinja2"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.forms.renderers.Jinja2</span></code></a><code class="docutils literal notranslate"><span class="pre">'</span></code></li>
</ul>
</div>
<div class="section" id="s-format-module-path">
<span id="s-std:setting-FORMAT_MODULE_PATH"></span><span id="format-module-path"></span><span id="std:setting-FORMAT_MODULE_PATH"></span><h3><code class="docutils literal notranslate"><span class="pre">FORMAT_MODULE_PATH</span></code><a class="headerlink" href="#format-module-path" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>一个 Python 包的完整 Python 路径，该 Python 包包含了项目 locale 的自定义格式定义。如果不是 <code class="docutils literal notranslate"><span class="pre">None</span></code>，Django 将检查当前 locale 目录下的 <code class="docutils literal notranslate"><span class="pre">formats.py</span></code> 文件，并将使用该文件中定义的格式。</p>
<p>例如，如果 <a class="reference internal" href="#std:setting-FORMAT_MODULE_PATH"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FORMAT_MODULE_PATH</span></code></a> 设置为 <code class="docutils literal notranslate"><span class="pre">mysite.</span> <span class="pre">formats</span></code>，当前语言为 <code class="docutils literal notranslate"><span class="pre">en</span></code> （英语），Django 将期望得到一个目录树，如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mysite</span><span class="o">/</span>
    <span class="n">formats</span><span class="o">/</span>
        <span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>
        <span class="n">en</span><span class="o">/</span>
            <span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>
            <span class="n">formats</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>你也可以将此设置为 Python 路径列表，例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">FORMAT_MODULE_PATH</span> <span class="o">=</span> <span class="p">[</span>
    <span class="s1">&#39;mysite.formats&#39;</span><span class="p">,</span>
    <span class="s1">&#39;some_app.formats&#39;</span><span class="p">,</span>
<span class="p">]</span>
</pre></div>
</div>
<p>当 Django 搜索某个格式时，它将通过所有给定的 Python 路径，直到找到一个真正定义该格式的模块。这意味着在列表中较远处的包中定义的格式将优先于较远处的包中的格式。</p>
<p>可用格式：</p>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DATE_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_INPUT_FORMATS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DATETIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATETIME_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DATETIME_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATETIME_INPUT_FORMATS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DECIMAL_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DECIMAL_SEPARATOR</span></code></a></li>
<li><a class="reference internal" href="#std:setting-FIRST_DAY_OF_WEEK"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FIRST_DAY_OF_WEEK</span></code></a></li>
<li><a class="reference internal" href="#std:setting-MONTH_DAY_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MONTH_DAY_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-NUMBER_GROUPING"><code class="xref std std-setting docutils literal notranslate"><span class="pre">NUMBER_GROUPING</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SHORT_DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SHORT_DATE_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SHORT_DATETIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SHORT_DATETIME_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-THOUSAND_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">THOUSAND_SEPARATOR</span></code></a></li>
<li><a class="reference internal" href="#std:setting-TIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-TIME_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_INPUT_FORMATS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-YEAR_MONTH_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">YEAR_MONTH_FORMAT</span></code></a></li>
</ul>
</div>
<div class="section" id="s-ignorable-404-urls">
<span id="s-std:setting-IGNORABLE_404_URLS"></span><span id="ignorable-404-urls"></span><span id="std:setting-IGNORABLE_404_URLS"></span><h3><code class="docutils literal notranslate"><span class="pre">IGNORABLE_404_URLS</span></code><a class="headerlink" href="#ignorable-404-urls" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>编译的正则表达式对象列表，这些对象描述了在通过电子邮件报告 HTTP 404 错误时应该被忽略的 URL（参见 <a class="reference internal" href="../howto/error-reporting.html"><span class="doc">发送错误</span></a>）。正则表达式与 <a class="reference internal" href="request-response.html#django.http.HttpRequest.get_full_path" title="django.http.HttpRequest.get_full_path"><code class="xref py py-meth docutils literal notranslate"><span class="pre">request</span> <span class="pre">的完整路径</span></code></a> （包括查询字符串，如果有的话）进行匹配。如果你的网站没有提供常用的请求文件，如 <code class="docutils literal notranslate"><span class="pre">favicon.ico</span></code> 或 <code class="docutils literal notranslate"><span class="pre">robots.txt</span></code>，请使用此选项。</p>
<p>只有当 <a class="reference internal" href="middleware.html#django.middleware.common.BrokenLinkEmailsMiddleware" title="django.middleware.common.BrokenLinkEmailsMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">BrokenLinkEmailsMiddleware</span></code></a> 被启用时，才会使用这个功能（参见 <a class="reference internal" href="../topics/http/middleware.html"><span class="doc">中间件</span></a>）。</p>
</div>
<div class="section" id="s-installed-apps">
<span id="s-std:setting-INSTALLED_APPS"></span><span id="installed-apps"></span><span id="std:setting-INSTALLED_APPS"></span><h3><code class="docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code><a class="headerlink" href="#installed-apps" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>一个字符串的列表，表示在这个 Django 安装中所有被启用的应用程序。每一个字符串都应该是一个 Python 的点分隔路径。</p>
<ul class="simple">
<li>应用程序配置类（首选），或</li>
<li>包含应用程序的包。</li>
</ul>
<p><a class="reference internal" href="applications.html"><span class="doc">了解更多关于应用配置</span></a>。</p>
<div class="admonition-use-the-application-registry-for-introspection admonition">
<p class="first admonition-title">使用应用程序注册进行自省</p>
<p class="last">你的代码不应该直接访问 <a class="reference internal" href="#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a>。使用 <a class="reference internal" href="applications.html#django.apps.apps" title="django.apps.apps"><code class="xref py py-attr docutils literal notranslate"><span class="pre">django.apps.apps</span></code></a> 代替。</p>
</div>
<div class="admonition-application-names-and-labels-must-be-unique-in-setting-installed-apps admonition">
<p class="first admonition-title">在 <code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTLED_APPS</span></code> 中，应用程序名称和标签必须是唯一的。</p>
<p>应用程序 <a class="reference internal" href="applications.html#django.apps.AppConfig.name" title="django.apps.AppConfig.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">名称</span></code></a> ——指向应用程序包的点分隔 Python 路径——必须是唯一的。没有办法将同一个应用程序包含两次，除非用另一个名字复制它的代码。</p>
<p>应用程序 <a class="reference internal" href="applications.html#django.apps.AppConfig.label" title="django.apps.AppConfig.label"><code class="xref py py-attr docutils literal notranslate"><span class="pre">标签</span></code></a> ——默认情况下，名称的最后一部分也必须是唯一的。例如，你不能同时包含 <code class="docutils literal notranslate"><span class="pre">django.contrib.auth</span></code> 和 <code class="docutils literal notranslate"><span class="pre">myproject.auth</span></code>。但是，你可以用自定义配置重新标注一个应用程序，定义不同的 <a class="reference internal" href="applications.html#django.apps.AppConfig.label" title="django.apps.AppConfig.label"><code class="xref py py-attr docutils literal notranslate"><span class="pre">label</span></code></a>。</p>
<p class="last">无论 <a class="reference internal" href="#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a> 引用的是应用程序配置类还是应用包，这些规则都适用。</p>
</div>
<p>当多个应用程序提供同一资源的不同版本（模板、静态文件、管理命令、翻译）时， <a class="reference internal" href="#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a> 中排在第一位的应用程序具有优先权。</p>
</div>
<div class="section" id="s-internal-ips">
<span id="s-std:setting-INTERNAL_IPS"></span><span id="internal-ips"></span><span id="std:setting-INTERNAL_IPS"></span><h3><code class="docutils literal notranslate"><span class="pre">INTERNAL_IPS</span></code><a class="headerlink" href="#internal-ips" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>一个 IP 地址的列表，作为字符串，它：</p>
<ul class="simple">
<li>允许 <a class="reference internal" href="templates/api.html#django.template.context_processors.debug" title="django.template.context_processors.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a> 上下文处理器为模板上下文添加一些变量。</li>
<li>即使不以员工用户身份登录，也可以使用 <a class="reference internal" href="contrib/admin/admindocs.html#admindocs-bookmarklets"><span class="std std-ref">管理文档书签</span></a>。</li>
<li>在 <a class="reference internal" href="../topics/logging.html#django.utils.log.AdminEmailHandler" title="django.utils.log.AdminEmailHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">AdminEmailHandler</span></code></a> 邮件中被标记为“internal”（与 “EXTERNAL”相对）。</li>
</ul>
</div>
<div class="section" id="s-language-code">
<span id="s-std:setting-LANGUAGE_CODE"></span><span id="language-code"></span><span id="std:setting-LANGUAGE_CODE"></span><h3><code class="docutils literal notranslate"><span class="pre">LANGUAGE_CODE</span></code><a class="headerlink" href="#language-code" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'en-us'</span></code></p>
<p>代表本次安装的语言代码的字符串。这应该是标准的 <a class="reference internal" href="../topics/i18n/index.html#term-language-code"><span class="xref std std-term">language ID 格式</span></a>。例如，美国英语是 <code class="docutils literal notranslate"><span class="pre">&quot;en-us&quot;</span></code>。也请参见 <a class="reference external" href="http://www.i18nguy.com/unicode/language-identifiers.html">语言标识符列表</a> 和 <a class="reference internal" href="../topics/i18n/index.html"><span class="doc">国际化和本地化</span></a>。</p>
<p>:setting:<a href="#id1"><span class="problematic" id="id2">`</span></a>USE_I18N' 必须是激活状态，该配置才会有效果。</p>
<p>它有两个作用：</p>
<ul class="simple">
<li>如果没有使用 locale 中间件，它决定向所有用户提供哪种翻译。</li>
<li>如果 locale 中间件是激活的，它提供了一个后备语言，以防用户的首选语言无法确定或网站不支持。当用户的首选语言不存在给定字词的翻译时，它也会提供后备翻译。</li>
</ul>
<p>更多细节请参考 <a class="reference internal" href="../topics/i18n/translation.html#how-django-discovers-language-preference"><span class="std std-ref">Django 如何发现语言偏好</span></a>。</p>
</div>
<div class="section" id="s-language-cookie-age">
<span id="s-std:setting-LANGUAGE_COOKIE_AGE"></span><span id="language-cookie-age"></span><span id="std:setting-LANGUAGE_COOKIE_AGE"></span><h3><code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_AGE</span></code><a class="headerlink" href="#language-cookie-age" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code> （浏览器关闭时失效）</p>
<p>语言 cookie 的寿命，以秒为单位</p>
</div>
<div class="section" id="s-language-cookie-domain">
<span id="s-std:setting-LANGUAGE_COOKIE_DOMAIN"></span><span id="language-cookie-domain"></span><span id="std:setting-LANGUAGE_COOKIE_DOMAIN"></span><h3><code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_DOMAIN</span></code><a class="headerlink" href="#language-cookie-domain" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>语言 cookie 使用的域。将其设置为一个字符串，如 <code class="docutils literal notranslate"><span class="pre">&quot;example.com&quot;</span></code> 用于跨域 cookie，或使用 <code class="docutils literal notranslate"><span class="pre">None</span></code> 用于标准域 cookie。</p>
<p>在生产型网站上更新此配置时要谨慎。如果你更新此配置，在以前使用标准域 cookie 的网站上启用跨域 cookie，则现有的具有旧域的用户 cookie 将不会被更新。这将导致网站用户无法切换语言，只要这些 cookie 持续存在。执行切换的唯一安全可靠的方案是永久更改语言 cookie 名称（通过 <a class="reference internal" href="#std:setting-LANGUAGE_COOKIE_NAME"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_NAME</span></code></a> 设置），并添加一个中间件，将旧 cookie 的值复制到新 cookie 中，然后删除旧 cookie。</p>
</div>
<div class="section" id="s-language-cookie-httponly">
<span id="s-std:setting-LANGUAGE_COOKIE_HTTPONLY"></span><span id="language-cookie-httponly"></span><span id="std:setting-LANGUAGE_COOKIE_HTTPONLY"></span><h3><code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_HTTPONLY</span></code><a class="headerlink" href="#language-cookie-httponly" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>是否对语言 cookie 使用 <code class="docutils literal notranslate"><span class="pre">HttpOnly</span></code> 标志。如果设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，客户端的 JavaScript 将无法访问语言 cookie。</p>
<p>关于 <code class="docutils literal notranslate"><span class="pre">HttpOnly</span></code> 的详细信息，请参见 <a class="reference internal" href="#std:setting-SESSION_COOKIE_HTTPONLY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SESSION_COOKIE_HTTPONLY</span></code></a>。</p>
</div>
<div class="section" id="s-language-cookie-name">
<span id="s-std:setting-LANGUAGE_COOKIE_NAME"></span><span id="language-cookie-name"></span><span id="std:setting-LANGUAGE_COOKIE_NAME"></span><h3><code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_NAME</span></code><a class="headerlink" href="#language-cookie-name" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'django_language'</span></code></p>
<p>用于语言 cookie 的 cookie 名称。这可以是任何你想要的（只要它与你的应用程序中的其他 cookie 名称不同）。参见 <a class="reference internal" href="../topics/i18n/index.html"><span class="doc">国际化和本地化</span></a>。</p>
</div>
<div class="section" id="s-language-cookie-path">
<span id="s-std:setting-LANGUAGE_COOKIE_PATH"></span><span id="language-cookie-path"></span><span id="std:setting-LANGUAGE_COOKIE_PATH"></span><h3><code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_PATH</span></code><a class="headerlink" href="#language-cookie-path" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'/'</span></code></p>
<p>语言 cookie 上设置的路径。这个路径应该与你的 Django 安装的 URL 路径相匹配，或者是该路径的父路径。</p>
<p>如果你有多个 Django 实例在同一个主机名下运行，这个功能很有用。他们可以使用不同的 cookie 路径，每个实例只能看到自己的语言 cookie。</p>
<p>在生产型网站上更新此配置时要谨慎。如果你更新此配置，使用比以前更深的路径，则现有的用户 cookie 的旧路径将不会被更新。这将导致网站用户无法切换语言，只要这些 cookie 持续存在。执行切换的唯一安全可靠的方案是永久更改语言 cookie 的名称（通过 <a class="reference internal" href="#std:setting-LANGUAGE_COOKIE_NAME"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_NAME</span></code></a> 配置），并添加一个中间件，将旧 cookie 的值复制到新的 cookie 中，然后删除这个 cookie。</p>
</div>
<div class="section" id="s-language-cookie-samesite">
<span id="s-std:setting-LANGUAGE_COOKIE_SAMESITE"></span><span id="language-cookie-samesite"></span><span id="std:setting-LANGUAGE_COOKIE_SAMESITE"></span><h3><code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_SAMESITE</span></code><a class="headerlink" href="#language-cookie-samesite" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>语言 cookie 上 <a class="reference external" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite">SameSite</a> 标志的值。该标志可防止在跨站点请求中发送 cookie。</p>
<p>关于 <code class="docutils literal notranslate"><span class="pre">SameSite</span></code> 的详细信息，请参见 <a class="reference internal" href="#std:setting-SESSION_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SESSION_COOKIE_SAMESITE</span></code></a>。</p>
<div class="versionchanged">
<span class="title">Changed in Django 3.1:</span> <p>允许设置 <code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_SAMESITE</span> <span class="pre">=</span> <span class="pre">'None'</span></code>。</p>
</div>
</div>
<div class="section" id="s-language-cookie-secure">
<span id="s-std:setting-LANGUAGE_COOKIE_SECURE"></span><span id="language-cookie-secure"></span><span id="std:setting-LANGUAGE_COOKIE_SECURE"></span><h3><code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_SECURE</span></code><a class="headerlink" href="#language-cookie-secure" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>是否对语言 cookie 使用安全 cookie。如果设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，cookie 将被标记为“安全”，这意味着浏览器可以确保 cookie 只在 HTTPS 连接下发送。</p>
</div>
<div class="section" id="s-languages">
<span id="s-std:setting-LANGUAGES"></span><span id="languages"></span><span id="std:setting-LANGUAGES"></span><h3><code class="docutils literal notranslate"><span class="pre">LANGUAGES</span></code><a class="headerlink" href="#languages" title="永久链接至标题">¶</a></h3>
<p>默认值。所有可用语言的清单。这个列表在不断的增加，如果在这里加入一个副本，那么不可避免的会很快过时。你可以在 <a class="reference external" href="https://github.com/django/django/blob/main/django/conf/global_settings.py">django/conf/global_settings.py</a> 中查看当前的翻译语言列表。</p>
<p>该列表是一个由两个元组组成的列表，其格式为 (<a class="reference internal" href="../topics/i18n/index.html#term-language-code"><span class="xref std std-term">language code</span></a>, <code class="docutils literal notranslate"><span class="pre">language</span> <span class="pre">name</span></code>) ——例如，<code class="docutils literal notranslate"><span class="pre">('ja',</span> <span class="pre">'Japanese')</span></code>。这指定了哪些语言可以选择。见 <a class="reference internal" href="../topics/i18n/index.html"><span class="doc">国际化和本地化</span></a>。</p>
<p>一般来说，默认值就可以了。只有当你想将语言选择限制在 Django 提供的语言子集时，才需要设置此配置。</p>
<p>如果你定义了一个自定义的 <a class="reference internal" href="#std:setting-LANGUAGES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGES</span></code></a> 配置，你可以使用 <a class="reference internal" href="utils.html#django.utils.translation.gettext_lazy" title="django.utils.translation.gettext_lazy"><code class="xref py py-func docutils literal notranslate"><span class="pre">gettext_lazy()</span></code></a> 函数将语言名称标记为翻译字符串。</p>
<p>以下是一个示例配置文件：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.utils.translation</span> <span class="kn">import</span> <span class="n">gettext_lazy</span> <span class="k">as</span> <span class="n">_</span>

<span class="n">LANGUAGES</span> <span class="o">=</span> <span class="p">[</span>
    <span class="p">(</span><span class="s1">&#39;de&#39;</span><span class="p">,</span> <span class="n">_</span><span class="p">(</span><span class="s1">&#39;German&#39;</span><span class="p">)),</span>
    <span class="p">(</span><span class="s1">&#39;en&#39;</span><span class="p">,</span> <span class="n">_</span><span class="p">(</span><span class="s1">&#39;English&#39;</span><span class="p">)),</span>
<span class="p">]</span>
</pre></div>
</div>
</div>
<div class="section" id="s-languages-bidi">
<span id="s-std:setting-LANGUAGES_BIDI"></span><span id="languages-bidi"></span><span id="std:setting-LANGUAGES_BIDI"></span><h3><code class="docutils literal notranslate"><span class="pre">LANGUAGES_BIDI</span></code><a class="headerlink" href="#languages-bidi" title="永久链接至标题">¶</a></h3>
<p>默认值。所有从右到左书写的语言代码的列表。你可以在 <a class="reference external" href="https://github.com/django/django/blob/main/django/conf/global_settings.py">django/conf/global_settings.py</a> 中查看这些语言的当前列表。</p>
<p>列表中包含 <a class="reference internal" href="../topics/i18n/index.html#term-language-code"><span class="xref std std-term">语言代码</span></a>，用于从右到左书写的语言。</p>
<p>一般来说，默认值就可以了。只有当你想将语言选择限制在 Django 提供的语言子集时，才设置这个配置。如果你定义了一个自定义的 <a class="reference internal" href="#std:setting-LANGUAGES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGES</span></code></a> 配置，双向语言列表中可能会包含一些在特定网站上没有启用的语言代码。</p>
</div>
<div class="section" id="s-locale-paths">
<span id="s-std:setting-LOCALE_PATHS"></span><span id="locale-paths"></span><span id="std:setting-LOCALE_PATHS"></span><h3><code class="docutils literal notranslate"><span class="pre">LOCALE_PATHS</span></code><a class="headerlink" href="#locale-paths" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>Django 寻找翻译文件的目录列表。参见 <a class="reference internal" href="../topics/i18n/translation.html#how-django-discovers-translations"><span class="std std-ref">Django 如何发现翻译</span></a>。</p>
<p>举例：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">LOCALE_PATHS</span> <span class="o">=</span> <span class="p">[</span>
    <span class="s1">&#39;/home/www/project/common_files/locale&#39;</span><span class="p">,</span>
    <span class="s1">&#39;/var/local/translations/locale&#39;</span><span class="p">,</span>
<span class="p">]</span>
</pre></div>
</div>
<p>Django 会在这些路径中寻找包含实际翻译文件的 <code class="docutils literal notranslate"><span class="pre">&lt;locale_code&gt;/LC_MESSAGES</span></code> 目录。</p>
</div>
<div class="section" id="s-logging">
<span id="s-std:setting-LOGGING"></span><span id="logging"></span><span id="std:setting-LOGGING"></span><h3><code class="docutils literal notranslate"><span class="pre">LOGGING</span></code><a class="headerlink" href="#logging" title="永久链接至标题">¶</a></h3>
<p>默认：日志配置字典。</p>
<p>一个包含配置信息的数据结构。该数据结构的内容将作为参数传递给 <a class="reference internal" href="#std:setting-LOGGING_CONFIG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LOGGING_CONFIG</span></code></a> 中描述的配置方法。</p>
<p>其中，当 <a class="reference internal" href="#std:setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code> 时，默认的日志配置会将 HTTP 500 服务器错误传递给电子邮件日志处理程序。也请参见 <a class="reference internal" href="../topics/logging.html#configuring-logging"><span class="std std-ref">日志模块的配置</span></a>。</p>
<p>你可以通过查看 <a class="reference external" href="https://github.com/django/django/blob/main/django/utils/log.py">django/utils/log.py</a> 中的默认日志配置。</p>
</div>
<div class="section" id="s-logging-config">
<span id="s-std:setting-LOGGING_CONFIG"></span><span id="logging-config"></span><span id="std:setting-LOGGING_CONFIG"></span><h3><code class="docutils literal notranslate"><span class="pre">LOGGING_CONFIG</span></code><a class="headerlink" href="#logging-config" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'logging.config.dictConfig'</span></code></p>
<p>Django 项目中用于配置日志的可调用路径。默认指向 Python 的 <a class="reference external" href="https://docs.python.org/3/library/logging.config.html#logging-config-dictschema" title="(在 Python v3.10)"><span class="xref std std-ref">dictConfig</span></a> 配置方法的实例。</p>
<p>如果将 <a class="reference internal" href="#std:setting-LOGGING_CONFIG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LOGGING_CONFIG</span></code></a> 配置为 <code class="docutils literal notranslate"><span class="pre">None</span></code>，将跳过日志配置过程。</p>
</div>
<div class="section" id="s-managers">
<span id="s-std:setting-MANAGERS"></span><span id="managers"></span><span id="std:setting-MANAGERS"></span><h3><code class="docutils literal notranslate"><span class="pre">MANAGERS</span></code><a class="headerlink" href="#managers" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>一个与 <a class="reference internal" href="#std:setting-ADMINS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">ADMINS</span></code></a> 格式相同的列表，用于指定当 <a class="reference internal" href="middleware.html#django.middleware.common.BrokenLinkEmailsMiddleware" title="django.middleware.common.BrokenLinkEmailsMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">BrokenLinkEmailsMiddleware</span></code></a> 被启用时，谁应该收到断链通知。</p>
</div>
<div class="section" id="s-media-root">
<span id="s-std:setting-MEDIA_ROOT"></span><span id="media-root"></span><span id="std:setting-MEDIA_ROOT"></span><h3><code class="docutils literal notranslate"><span class="pre">MEDIA_ROOT</span></code><a class="headerlink" href="#media-root" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>保存 <a class="reference internal" href="../topics/files.html"><span class="doc">用户上传的文件</span></a> 目录的绝对文件系统路径。</p>
<p>例如： <code class="docutils literal notranslate"><span class="pre">&quot;/var/www/example.com/media/&quot;</span></code></p>
<p>另见 <a class="reference internal" href="#std:setting-MEDIA_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MEDIA_URL</span></code></a>。</p>
<div class="admonition warning">
<p class="first admonition-title">警告</p>
<p class="last"><a class="reference internal" href="#std:setting-MEDIA_ROOT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MEDIA_ROOT</span></code></a> 和 <a class="reference internal" href="#std:setting-STATIC_ROOT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_ROOT</span></code></a> 必须有不同的值。在引入 <a class="reference internal" href="#std:setting-STATIC_ROOT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_ROOT</span></code></a> 之前，通常依靠或回溯 <a class="reference internal" href="#std:setting-MEDIA_ROOT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MEDIA_ROOT</span></code></a> 来提供静态文件；然而，由于这可能会产生严重的安全影响，因此有一个验证检查来防止这种情况。</p>
</div>
</div>
<div class="section" id="s-media-url">
<span id="s-std:setting-MEDIA_URL"></span><span id="media-url"></span><span id="std:setting-MEDIA_URL"></span><h3><code class="docutils literal notranslate"><span class="pre">MEDIA_URL</span></code><a class="headerlink" href="#media-url" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>处理从 <a class="reference internal" href="#std:setting-MEDIA_ROOT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MEDIA_ROOT</span></code></a> 提供的媒体的 URL，用于 <a class="reference internal" href="../topics/files.html"><span class="doc">管理存储文件</span></a>。如果设置为非空值，则必须以斜线结束。在开发和生产环境中，你都需要 <a class="reference internal" href="../howto/static-files/index.html#serving-uploaded-files-in-development"><span class="std std-ref">配置这些文件被服务</span></a>。</p>
<p>如果你想在模板中使用 <code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">MEDIA_URL</span> <span class="pre">}}</span></code>，在 <a class="reference internal" href="#std:setting-TEMPLATES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TEMPLATES</span></code></a> 的 <code class="docutils literal notranslate"><span class="pre">''context_processors'</span></code> 选项中添加 <code class="docutils literal notranslate"><span class="pre">'django.template.context_processors.media'</span></code>。</p>
<p>例如： <code class="docutils literal notranslate"><span class="pre">&quot;http://media.example.com/&quot;</span></code></p>
<div class="admonition warning">
<p class="first admonition-title">警告</p>
<p class="last">如果接收不受信任的用户的上传会有安全隐患， 请阅读 <a class="reference internal" href="../topics/security.html#user-uploaded-content-security"><span class="std std-ref">用户上传内容</span></a> 获取详情.</p>
</div>
<div class="admonition warning">
<p class="first admonition-title">警告</p>
<p class="last"><a class="reference internal" href="#std:setting-MEDIA_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MEDIA_URL</span></code></a> 和 <a class="reference internal" href="#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a> 必须有不同的值。更多细节请参见 <a class="reference internal" href="#std:setting-MEDIA_ROOT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MEDIA_ROOT</span></code></a>。</p>
</div>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">如果 <a class="reference internal" href="#std:setting-MEDIA_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MEDIA_URL</span></code></a> 是一个相对路径，那么它将以服务器提供的 <code class="docutils literal notranslate"><span class="pre">SCRIPT_NAME</span></code> 的值为前缀（如果没有设置，则为 <code class="docutils literal notranslate"><span class="pre">/</span></code>）。这使得在子路径中服务 Django 应用时更容易，而无需额外增加配置。</p>
</div>
</div>
<div class="section" id="s-middleware">
<span id="s-std:setting-MIDDLEWARE"></span><span id="middleware"></span><span id="std:setting-MIDDLEWARE"></span><h3><code class="docutils literal notranslate"><span class="pre">MIDDLEWARE</span></code><a class="headerlink" href="#middleware" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>要使用的中间件列表。参见 <a class="reference internal" href="../topics/http/middleware.html"><span class="doc">中间件</span></a>。</p>
</div>
<div class="section" id="s-migration-modules">
<span id="s-std:setting-MIGRATION_MODULES"></span><span id="migration-modules"></span><span id="std:setting-MIGRATION_MODULES"></span><h3><code class="docutils literal notranslate"><span class="pre">MIGRATION_MODULES</span></code><a class="headerlink" href="#migration-modules" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">{}</span></code> （空字典）</p>
<p>一个指定包的字典，在每个应用程序的基础上可以找到迁移模块。这个配置的默认值是一个空字典，但迁移模块的默认包名是 <code class="docutils literal notranslate"><span class="pre">migrations</span></code>。</p>
<p>举例：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span><span class="s1">&#39;blog&#39;</span><span class="p">:</span> <span class="s1">&#39;blog.db_migrations&#39;</span><span class="p">}</span>
</pre></div>
</div>
<p>在这种情况下，与 <code class="docutils literal notranslate"><span class="pre">blog</span></code> 应用有关的迁移将包含在 <code class="docutils literal notranslate"><span class="pre">blog.db_migrations</span></code> 包中。</p>
<p>如果你提供了 <code class="docutils literal notranslate"><span class="pre">app_label</span></code> 参数， <a class="reference internal" href="django-admin.html#django-admin-makemigrations"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">makemigrations</span></code></a> 将自动创建包，如果它还不存在。</p>
<p>当你为一个应用程序提供 <code class="docutils literal notranslate"><span class="pre">None</span></code> 作为一个值时，Django 会将该应用程序视为一个没有迁移的应用程序，而不考虑是否存在 <code class="docutils literal notranslate"><span class="pre">migrations</span></code> 子模块。例如，在测试设置文件中，这可以用来在测试时跳过迁移（仍然会为应用程序的模型创建表）。要在测试期间禁止所有应用程序的迁移，你可以将 <a class="reference internal" href="#std:setting-TEST_MIGRATE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MIGRATE</span></code></a> 设置为 <code class="docutils literal notranslate"><span class="pre">False</span></code>。如果在你的一般项目配置中使用了 <code class="docutils literal notranslate"><span class="pre">MIGRATION_MODULES</span></code>，如果你想为应用程序创建表，记得使用 <a class="reference internal" href="django-admin.html#cmdoption-migrate-run-syncdb"><code class="xref std std-option docutils literal notranslate"><span class="pre">migrate</span> <span class="pre">--run-syncdb</span></code></a> 选项。</p>
</div>
<div class="section" id="s-month-day-format">
<span id="s-std:setting-MONTH_DAY_FORMAT"></span><span id="month-day-format"></span><span id="std:setting-MONTH_DAY_FORMAT"></span><h3><code class="docutils literal notranslate"><span class="pre">MONTH_DAY_FORMAT</span></code><a class="headerlink" href="#month-day-format" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'F</span> <span class="pre">j'</span></code></p>
<p>在 Django admin change-list 页面上的日期字段的默认格式——也可能被系统的其他部分使用——在只显示月份和日期的情况下。</p>
<p>例如，当 Django 管理员的变更列表页面被日期 drilldown 过滤时，给定的一天的标题会显示日期和月份。不同的地域有不同的格式。例如，美国英语会说“January 1”，而西班牙语可能会说“1 Enero”。</p>
<p>请注意，如果 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，则相应的本地决定的格式具有更高的优先权，并将被应用。</p>
<p>查看 <a class="reference internal" href="templates/builtins.html#std:templatefilter-date"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">允许的日期格式字符串</span></code></a>。另见 <a class="reference internal" href="#std:setting-DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_FORMAT</span></code></a>、<a class="reference internal" href="#std:setting-DATETIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATETIME_FORMAT</span></code></a>、<a class="reference internal" href="#std:setting-TIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_FORMAT</span></code></a> 和 <a class="reference internal" href="#std:setting-YEAR_MONTH_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">YEAR_MONTH_FORMAT</span></code></a>。</p>
</div>
<div class="section" id="s-number-grouping">
<span id="s-std:setting-NUMBER_GROUPING"></span><span id="number-grouping"></span><span id="std:setting-NUMBER_GROUPING"></span><h3><code class="docutils literal notranslate"><span class="pre">NUMBER_GROUPING</span></code><a class="headerlink" href="#number-grouping" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">0</span></code></p>
<p>一个数字的整数部分的数字组合在一起的数量。</p>
<p>常见的用途是显示千位数的分隔符。如果该设置为 <code class="docutils literal notranslate"><span class="pre">0</span></code>，则不会对该数字进行分组。如果这个设置大于 <code class="docutils literal notranslate"><span class="pre">0</span></code>，那么 <a class="reference internal" href="#std:setting-THOUSAND_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">THOUSAND_SEPARATOR</span></code></a> 将被用作这些组之间的分隔符。</p>
<p>有些地方使用非统一的数字分组，例如 <code class="docutils literal notranslate"><span class="pre">en_IN</span></code> 中的 <code class="docutils literal notranslate"><span class="pre">10,00,00,000</span></code>。对于这种情况，你可以提供一个序列，其中包含要应用的数字组大小。第一个数字定义小数定界符之前的组的大小，后面的每个数字定义前面组的大小。如果序列以 <code class="docutils literal notranslate"><span class="pre">-1</span></code> 结束，则不会再进行分组。如果序列以 <code class="docutils literal notranslate"><span class="pre">0</span></code> 结束，则在剩余的数字中使用最后一组的大小。</p>
<p><code class="docutils literal notranslate"><span class="pre">en_IN</span></code> 的元组示例：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">NUMBER_GROUPING</span> <span class="o">=</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
<p>请注意，如果 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，那么将采用本地决定的格式，具有更高的优先权。</p>
<p>另见 <a class="reference internal" href="#std:setting-DECIMAL_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DECIMAL_SEPARATOR</span></code></a>、<a class="reference internal" href="#std:setting-THOUSAND_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">THOUSAND_SEPARATOR</span></code></a> 和 <a class="reference internal" href="#std:setting-USE_THOUSAND_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_THOUSAND_SEPARATOR</span></code></a>。</p>
</div>
<div class="section" id="s-prepend-www">
<span id="s-std:setting-PREPEND_WWW"></span><span id="prepend-www"></span><span id="std:setting-PREPEND_WWW"></span><h3><code class="docutils literal notranslate"><span class="pre">PREPEND_WWW</span></code><a class="headerlink" href="#prepend-www" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>是否给没有“www.”子域的 URL 加前缀。只有在安装了 <a class="reference internal" href="middleware.html#django.middleware.common.CommonMiddleware" title="django.middleware.common.CommonMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">CommonMiddleware</span></code></a> 的情况下才会使用（参见 <a class="reference internal" href="../topics/http/middleware.html"><span class="doc">中间件</span></a>）。也请参见 <a class="reference internal" href="#std:setting-APPEND_SLASH"><code class="xref std std-setting docutils literal notranslate"><span class="pre">APPEND_SLASH</span></code></a>。</p>
</div>
<div class="section" id="s-root-urlconf">
<span id="s-std:setting-ROOT_URLCONF"></span><span id="root-urlconf"></span><span id="std:setting-ROOT_URLCONF"></span><h3><code class="docutils literal notranslate"><span class="pre">ROOT_URLCONF</span></code><a class="headerlink" href="#root-urlconf" title="永久链接至标题">¶</a></h3>
<p>默认：未定义</p>
<p>一个字符串，代表你的根 URLconf 的完整 Python 导入路径，例如 <code class="docutils literal notranslate"><span class="pre">&quot;mydjangoapps.urls&quot;</span></code>。可以通过在传入的 <code class="docutils literal notranslate"><span class="pre">HttpRequest</span></code> 对象上设置属性 <code class="docutils literal notranslate"><span class="pre">urlconf</span></code> 来覆盖每个请求。详情请参见 <a class="reference internal" href="../topics/http/urls.html#how-django-processes-a-request"><span class="std std-ref">Django 如何处理一个请求</span></a>。</p>
</div>
<div class="section" id="s-secret-key">
<span id="s-std:setting-SECRET_KEY"></span><span id="secret-key"></span><span id="std:setting-SECRET_KEY"></span><h3><code class="docutils literal notranslate"><span class="pre">SECRET_KEY</span></code><a class="headerlink" href="#secret-key" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>一个特定 Django 安装的密钥。用于提供 <a class="reference internal" href="../topics/signing.html"><span class="doc">加密签名</span></a>，并且应该设置为一个唯一的、不可预测的值。</p>
<p><a class="reference internal" href="django-admin.html#django-admin-startproject"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">django-admin</span> <span class="pre">startproject</span></code></a> 自动为每个新项目添加一个随机生成的 <code class="docutils literal notranslate"><span class="pre">SECRET_KEY</span></code>。</p>
<p>键的使用不应该假设是文本或字节。每次使用都应该通过 <a class="reference internal" href="utils.html#django.utils.encoding.force_str" title="django.utils.encoding.force_str"><code class="xref py py-func docutils literal notranslate"><span class="pre">force_str()</span></code></a> 或 <a class="reference internal" href="utils.html#django.utils.encoding.force_bytes" title="django.utils.encoding.force_bytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">force_bytes()</span></code></a> 将其转换为所需类型。</p>
<p>如果 <a class="reference internal" href="#std:setting-SECRET_KEY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECRET_KEY</span></code></a> 没有设置，Django 将拒绝启动。</p>
<div class="admonition warning">
<p class="first admonition-title">警告</p>
<p><strong>将此值保密。</strong></p>
<p class="last">在已知的 <a class="reference internal" href="#std:setting-SECRET_KEY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECRET_KEY</span></code></a> 的情况下运行 Django，会破坏 Django 的许多安全保护措施，并可能导致权限升级和远程代码执行漏洞。</p>
</div>
<p>密钥用于：</p>
<ul class="simple">
<li>所有 <a class="reference internal" href="../topics/http/sessions.html"><span class="doc">会话</span></a> 如果你使用的是 <code class="docutils literal notranslate"><span class="pre">django.contrib.session.backends.cache</span></code> 以外的任何其他会话后端，或者使用的是默认的 <a class="reference internal" href="../topics/auth/customizing.html#django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash" title="django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_session_auth_hash()</span></code></a>。</li>
<li>所有 <a class="reference internal" href="contrib/messages.html"><span class="doc">消息</span></a>，如果你使用了 <a class="reference internal" href="contrib/messages.html#django.contrib.messages.storage.cookie.CookieStorage" title="django.contrib.messages.storage.cookie.CookieStorage"><code class="xref py py-class docutils literal notranslate"><span class="pre">CookieStorage</span></code></a> 或 <a class="reference internal" href="contrib/messages.html#django.contrib.messages.storage.fallback.FallbackStorage" title="django.contrib.messages.storage.fallback.FallbackStorage"><code class="xref py py-class docutils literal notranslate"><span class="pre">FallbackStorage</span></code></a>。</li>
<li>所有 <a class="reference internal" href="../topics/auth/default.html#django.contrib.auth.views.PasswordResetView" title="django.contrib.auth.views.PasswordResetView"><code class="xref py py-class docutils literal notranslate"><span class="pre">PasswordResetView</span></code></a> 密钥。</li>
<li><a class="reference internal" href="../topics/signing.html"><span class="doc">加密签名</span></a> 的任何使用，除非提供不同的密钥。</li>
</ul>
<p>如果你轮换密钥，以上都将失效。密钥不用于用户的密码，轮换秘钥不会影响用户的密码。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">默认的 <code class="file docutils literal notranslate"><span class="pre">settings.py</span></code> 文件由 <a class="reference internal" href="django-admin.html#django-admin-startproject"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">django-admin</span> <span class="pre">startproject</span></code></a> 创建，为方便起见，创建了一个唯一的 <code class="docutils literal notranslate"><span class="pre">SECRET_KEY</span></code>。</p>
</div>
</div>
<div class="section" id="s-secure-browser-xss-filter">
<span id="s-std:setting-SECURE_BROWSER_XSS_FILTER"></span><span id="secure-browser-xss-filter"></span><span id="std:setting-SECURE_BROWSER_XSS_FILTER"></span><h3><code class="docutils literal notranslate"><span class="pre">SECURE_BROWSER_XSS_FILTER</span></code><a class="headerlink" href="#secure-browser-xss-filter" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>如果 <code class="docutils literal notranslate"><span class="pre">True</span></code>，则 <a class="reference internal" href="middleware.html#django.middleware.security.SecurityMiddleware" title="django.middleware.security.SecurityMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecurityMiddleware</span></code></a> 会在所有响应中设置 <a class="reference internal" href="middleware.html#x-xss-protection"><span class="std std-ref">X-XSS-Protection: 1; mode=block</span></a> 头。</p>
<p>现代浏览器已经不再使用 <code class="docutils literal notranslate"><span class="pre">X-XSS-Protection</span></code> HTTP头。虽然这个配置没有什么实际的好处，但是如果你支持旧的浏览器，你可能还是要设置这个头。</p>
</div>
<div class="section" id="s-secure-content-type-nosniff">
<span id="s-std:setting-SECURE_CONTENT_TYPE_NOSNIFF"></span><span id="secure-content-type-nosniff"></span><span id="std:setting-SECURE_CONTENT_TYPE_NOSNIFF"></span><h3><code class="docutils literal notranslate"><span class="pre">SECURE_CONTENT_TYPE_NOSNIFF</span></code><a class="headerlink" href="#secure-content-type-nosniff" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">True</span></code></p>
<p>如果 <code class="docutils literal notranslate"><span class="pre">True</span></code>，则 <a class="reference internal" href="middleware.html#django.middleware.security.SecurityMiddleware" title="django.middleware.security.SecurityMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecurityMiddleware</span></code></a> 会在所有响应中设置 <a class="reference internal" href="middleware.html#x-content-type-options"><span class="std std-ref">X-Content-Type-Options: nosniff</span></a> 头。</p>
</div>
<div class="section" id="s-secure-hsts-include-subdomains">
<span id="s-std:setting-SECURE_HSTS_INCLUDE_SUBDOMAINS"></span><span id="secure-hsts-include-subdomains"></span><span id="std:setting-SECURE_HSTS_INCLUDE_SUBDOMAINS"></span><h3><code class="docutils literal notranslate"><span class="pre">SECURE_HSTS_INCLUDE_SUBDOMAINS</span></code><a class="headerlink" href="#secure-hsts-include-subdomains" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>如果 <code class="docutils literal notranslate"><span class="pre">True</span></code>，则 <a class="reference internal" href="middleware.html#django.middleware.security.SecurityMiddleware" title="django.middleware.security.SecurityMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecurityMiddleware</span></code></a> 在 <a class="reference internal" href="middleware.html#http-strict-transport-security"><span class="std std-ref">HTTP 严格传输安全</span></a> 头中添加 <code class="docutils literal notranslate"><span class="pre">includeSubDomains</span></code> 指令。除非  <a class="reference internal" href="#std:setting-SECURE_HSTS_SECONDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_HSTS_SECONDS</span></code></a> 被设置为非零值，否则它没有任何效果。</p>
<div class="admonition warning">
<p class="first admonition-title">警告</p>
<p class="last">如果设置不正确，可能会不可逆地（对于 <a class="reference internal" href="#std:setting-SECURE_HSTS_SECONDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_HSTS_SECONDS</span></code></a> 的值）破坏你的网站。请先阅读 <a class="reference internal" href="middleware.html#http-strict-transport-security"><span class="std std-ref">HTTP 严格传输安全</span></a> 文档。</p>
</div>
</div>
<div class="section" id="s-secure-hsts-preload">
<span id="s-std:setting-SECURE_HSTS_PRELOAD"></span><span id="secure-hsts-preload"></span><span id="std:setting-SECURE_HSTS_PRELOAD"></span><h3><code class="docutils literal notranslate"><span class="pre">SECURE_HSTS_PRELOAD</span></code><a class="headerlink" href="#secure-hsts-preload" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>如果 <code class="docutils literal notranslate"><span class="pre">True</span></code>，则 <a class="reference internal" href="middleware.html#django.middleware.security.SecurityMiddleware" title="django.middleware.security.SecurityMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecurityMiddleware</span></code></a> 在 <a class="reference internal" href="middleware.html#http-strict-transport-security"><span class="std std-ref">HTTP 严格传输安全</span></a> 头中添加 <code class="docutils literal notranslate"><span class="pre">preload</span></code> 指令。除非 <a class="reference internal" href="#std:setting-SECURE_HSTS_SECONDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_HSTS_SECONDS</span></code></a> 设置为非零值，否则没有效果。</p>
</div>
<div class="section" id="s-secure-hsts-seconds">
<span id="s-std:setting-SECURE_HSTS_SECONDS"></span><span id="secure-hsts-seconds"></span><span id="std:setting-SECURE_HSTS_SECONDS"></span><h3><code class="docutils literal notranslate"><span class="pre">SECURE_HSTS_SECONDS</span></code><a class="headerlink" href="#secure-hsts-seconds" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">0</span></code></p>
<p>如果设置为非零的整数值，则 <a class="reference internal" href="middleware.html#django.middleware.security.SecurityMiddleware" title="django.middleware.security.SecurityMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecurityMiddleware</span></code></a> 会对所有尚未设置 <a class="reference internal" href="middleware.html#http-strict-transport-security"><span class="std std-ref">HTTP 严格传输安全</span></a> 头的响应进行设置。</p>
<div class="admonition warning">
<p class="first admonition-title">警告</p>
<p class="last">不正确的设置可能会不可逆地（在一段时间内）破坏你的网站。请先阅读 <a class="reference internal" href="middleware.html#http-strict-transport-security"><span class="std std-ref">HTTP 严格传输安全</span></a> 文档。</p>
</div>
</div>
<div class="section" id="s-secure-proxy-ssl-header">
<span id="s-std:setting-SECURE_PROXY_SSL_HEADER"></span><span id="secure-proxy-ssl-header"></span><span id="std:setting-SECURE_PROXY_SSL_HEADER"></span><h3><code class="docutils literal notranslate"><span class="pre">SECURE_PROXY_SSL_HEADER</span></code><a class="headerlink" href="#secure-proxy-ssl-header" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>代表 HTTP 头／值组合的元组，表示请求是安全的。这控制了请求对象的 <code class="docutils literal notranslate"><span class="pre">is_secure()</span></code> 方法的行为。</p>
<p>默认情况下，<code class="docutils literal notranslate"><span class="pre">is_secure()</span></code> 通过确认请求的 URL 使用 <code class="docutils literal notranslate"><span class="pre">https://</span></code> 来判断请求是否安全。这个方法对 Django 的 CSRF 保护很重要，你自己的代码或第三方应用可能会用到它。</p>
<p>如果你的 Django 应用是在代理服务器后面，那么无论原始请求是否使用 HTTPS，代理服务器都可能会“吞噬”。如果代理和 Django 之间有一个非 HTTPS 的连接，那么 <code class="docutils literal notranslate"><span class="pre">is_secure()</span></code> 总是返回 <code class="docutils literal notranslate"><span class="pre">False</span></code> ——即使是终端用户通过 HTTPS 发出的请求。相反，如果代理和 Django 之间有 HTTPS 连接，那么 <code class="docutils literal notranslate"><span class="pre">is_secure()</span></code> 将总是返回 <code class="docutils literal notranslate"><span class="pre">True</span></code> ——即使是对最终用户通过 HTTPS 发出的请求。</p>
<p>在这种情况下，配置你的代理服务器，设置一个自定义的 HTTP 头，告诉 Django 这个请求是否是通过 HTTPS 进来的，并设置 <code class="docutils literal notranslate"><span class="pre">SECURE_PROXY_SSL_HEADER</span></code>，这样 Django 就知道要找什么头了。</p>
<p>设置一个包含两个元素的元组——要查找的头的名称和所需的值。例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">SECURE_PROXY_SSL_HEADER</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;HTTP_X_FORWARDED_PROTO&#39;</span><span class="p">,</span> <span class="s1">&#39;https&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>这告诉 Django 信任来自我们代理的 <code class="docutils literal notranslate"><span class="pre">X-Forwarded-Proto</span></code> 头，任何时候它的值是 <code class="docutils literal notranslate"><span class="pre">'https'</span></code>，那么就保证请求是安全的（即原来是通过 HTTPS 进来的）。</p>
<p>如果你控制了你的代理或者有其他的保证，你应该 <em>只</em> 设置这个配置，它可以适当地设置／剥离这个头。</p>
<p>需要注意的是，头的格式需要和 <code class="docutils literal notranslate"><span class="pre">request.META</span></code> 使用的格式一样——全大写，并且可能以 <code class="docutils literal notranslate"><span class="pre">HTTP_</span></code> 开头。（记住，Django 会在 x-header 名称的开头自动加上 <code class="docutils literal notranslate"><span class="pre">'HTTP_'</span></code>，然后才会在 <code class="docutils literal notranslate"><span class="pre">request.META</span></code> 中使用。）</p>
<div class="admonition warning">
<p class="first admonition-title">警告</p>
<p><strong>修改此设置可能会危及你网站的安全。在更改之前，请确保你完全了解你的配置。</strong></p>
<p>在设置之前，请确保以下所有内容为真（假设上面例子中的数值）。</p>
<ul class="simple">
<li>你的 Django 应用在代理服务器后面。</li>
<li>你的代理将从所有传入的请求中剥离 <code class="docutils literal notranslate"><span class="pre">X-Forwarded-Proto</span></code> 头。换句话说，如果终端用户在他们的请求中包含了该头，代理将丢弃它。</li>
<li>你的代理设置了 <code class="docutils literal notranslate"><span class="pre">X-Forwarded-Proto</span></code> 头，并将其发送给 Django，但只针对最初通过 HTTPS 进来的请求。</li>
</ul>
<p class="last">如果其中任何一个不是真的，你应该将这个配置设置为 <code class="docutils literal notranslate"><span class="pre">None</span></code>，并找到另一种确定 HTTPS 的方法，也许是通过自定义中间件。</p>
</div>
</div>
<div class="section" id="s-secure-redirect-exempt">
<span id="s-std:setting-SECURE_REDIRECT_EXEMPT"></span><span id="secure-redirect-exempt"></span><span id="std:setting-SECURE_REDIRECT_EXEMPT"></span><h3><code class="docutils literal notranslate"><span class="pre">SECURE_REDIRECT_EXEMPT</span></code><a class="headerlink" href="#secure-redirect-exempt" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>如果一个 URL 路径与这个列表中的正则表达式相匹配，那么请求将不会被重定向到 HTTPS。<a class="reference internal" href="middleware.html#django.middleware.security.SecurityMiddleware" title="django.middleware.security.SecurityMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecurityMiddleware</span></code></a> 会从 URL 路径中去掉前导斜杠，所以模式不应该包含它们，例如 <code class="docutils literal notranslate"><span class="pre">SECURE_REDIRECT_EXEMPT</span> <span class="pre">=</span> <span class="pre">[r'^no-ssl/$',</span> <span class="pre">...]</span></code>。如果 <a class="reference internal" href="#std:setting-SECURE_SSL_REDIRECT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_SSL_REDIRECT</span></code></a> 是 <code class="docutils literal notranslate"><span class="pre">False</span></code>，这个配置就没有效果。</p>
</div>
<div class="section" id="s-secure-referrer-policy">
<span id="s-std:setting-SECURE_REFERRER_POLICY"></span><span id="secure-referrer-policy"></span><span id="std:setting-SECURE_REFERRER_POLICY"></span><h3><code class="docutils literal notranslate"><span class="pre">SECURE_REFERRER_POLICY</span></code><a class="headerlink" href="#secure-referrer-policy" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'same-origin'</span></code></p>
<p>如果设置了 <a class="reference internal" href="middleware.html#django.middleware.security.SecurityMiddleware" title="django.middleware.security.SecurityMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecurityMiddleware</span></code></a>，则会在所有响应中设置 :ref:<a href="#id1"><span class="problematic" id="id2">`</span></a>referrer-policy`头，如果还没有该头，则将其设置为提供的值。</p>
<div class="versionchanged">
<span class="title">Changed in Django 3.1:</span> <p>在旧版本中，默认值为 <code class="docutils literal notranslate"><span class="pre">None</span></code>。</p>
</div>
</div>
<div class="section" id="s-secure-ssl-host">
<span id="s-std:setting-SECURE_SSL_HOST"></span><span id="secure-ssl-host"></span><span id="std:setting-SECURE_SSL_HOST"></span><h3><code class="docutils literal notranslate"><span class="pre">SECURE_SSL_HOST</span></code><a class="headerlink" href="#secure-ssl-host" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>如果是一个字符串（如 <code class="docutils literal notranslate"><span class="pre">secure.example.com</span></code>），所有 SSL 重定向都将指向这个主机，而不是最初请求的主机（如 <code class="docutils literal notranslate"><span class="pre">www.example.com</span></code>）。如果 <a class="reference internal" href="#std:setting-SECURE_SSL_REDIRECT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_SSL_REDIRECT</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code>，则该配置没有效果。</p>
</div>
<div class="section" id="s-secure-ssl-redirect">
<span id="s-std:setting-SECURE_SSL_REDIRECT"></span><span id="secure-ssl-redirect"></span><span id="std:setting-SECURE_SSL_REDIRECT"></span><h3><code class="docutils literal notranslate"><span class="pre">SECURE_SSL_REDIRECT</span></code><a class="headerlink" href="#secure-ssl-redirect" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>如果 <code class="docutils literal notranslate"><span class="pre">True</span></code>，则 <a class="reference internal" href="middleware.html#django.middleware.security.SecurityMiddleware" title="django.middleware.security.SecurityMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecurityMiddleware</span></code></a> <a class="reference internal" href="middleware.html#ssl-redirect"><span class="std std-ref">重定向</span></a> 所有非 HTTPS 的请求都会转为 HTTPS（除了那些匹配 <a class="reference internal" href="#std:setting-SECURE_REDIRECT_EXEMPT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_REDIRECT_EXEMPT</span></code></a> 中所列正则表达式的 URL）。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">如果将此设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 会导致无限重定向，这可能意味着你的网站是在代理服务器后面运行的，并且无法判断哪些请求是安全的，哪些不是。你的代理服务器可能会设置一个头来指示安全请求；你可以通过找出该头并相应地配置 <a class="reference internal" href="#std:setting-SECURE_PROXY_SSL_HEADER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_PROXY_SSL_HEADER</span></code></a> 设置来纠正这个问题。</p>
</div>
</div>
<div class="section" id="s-serialization-modules">
<span id="s-std:setting-SERIALIZATION_MODULES"></span><span id="serialization-modules"></span><span id="std:setting-SERIALIZATION_MODULES"></span><h3><code class="docutils literal notranslate"><span class="pre">SERIALIZATION_MODULES</span></code><a class="headerlink" href="#serialization-modules" title="永久链接至标题">¶</a></h3>
<p>默认：未定义</p>
<p>一个包含序列化器定义（以字符串形式提供）的模块字典，以该序列化类型的字符串标识符为键。例如，要定义一个 YAML 序列化器，使用：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">SERIALIZATION_MODULES</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;yaml&#39;</span><span class="p">:</span> <span class="s1">&#39;path.to.yaml_serializer&#39;</span><span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="s-server-email">
<span id="s-std:setting-SERVER_EMAIL"></span><span id="server-email"></span><span id="std:setting-SERVER_EMAIL"></span><h3><code class="docutils literal notranslate"><span class="pre">SERVER_EMAIL</span></code><a class="headerlink" href="#server-email" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'root&#64;localhost'</span></code></p>
<p>错误信息来自的电子邮件地址，例如发送到 <a class="reference internal" href="#std:setting-ADMINS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">ADMINS</span></code></a> 和 <a class="reference internal" href="#std:setting-MANAGERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MANAGERS</span></code></a> 的邮件。</p>
<div class="admonition-why-are-my-emails-sent-from-a-different-address admonition">
<p class="first admonition-title">为什么我的邮件从不同的地址发送？</p>
<p class="last">这个地址只用于错误信息。它 <em>不是</em> 用 <a class="reference internal" href="../topics/email.html#django.core.mail.send_mail" title="django.core.mail.send_mail"><code class="xref py py-meth docutils literal notranslate"><span class="pre">send_mail()</span></code></a> 发送普通邮件的地址；关于这个地址，请看 <a class="reference internal" href="#std:setting-DEFAULT_FROM_EMAIL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_FROM_EMAIL</span></code></a>。</p>
</div>
</div>
<div class="section" id="s-short-date-format">
<span id="s-std:setting-SHORT_DATE_FORMAT"></span><span id="short-date-format"></span><span id="std:setting-SHORT_DATE_FORMAT"></span><h3><code class="docutils literal notranslate"><span class="pre">SHORT_DATE_FORMAT</span></code><a class="headerlink" href="#short-date-format" title="永久链接至标题">¶</a></h3>
<p>默认 ：<code class="docutils literal notranslate"><span class="pre">'m/d/Y'</span></code> （例如 <code class="docutils literal notranslate"><span class="pre">12/31/2003</span></code>）</p>
<p>可用于在模板上显示日期字段的可用格式。请注意，如果 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 被设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，那么相应的本地决定的格式具有更高的优先权，并将被应用。参见 <a class="reference internal" href="templates/builtins.html#std:templatefilter-date"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">允许的日期格式字符串</span></code></a>。</p>
<p>另见 <a class="reference internal" href="#std:setting-DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_FORMAT</span></code></a> 和 <a class="reference internal" href="#std:setting-SHORT_DATETIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SHORT_DATETIME_FORMAT</span></code></a>。</p>
</div>
<div class="section" id="s-short-datetime-format">
<span id="s-std:setting-SHORT_DATETIME_FORMAT"></span><span id="short-datetime-format"></span><span id="std:setting-SHORT_DATETIME_FORMAT"></span><h3><code class="docutils literal notranslate"><span class="pre">SHORT_DATETIME_FORMAT</span></code><a class="headerlink" href="#short-datetime-format" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'m/d/Y</span> <span class="pre">P'</span></code> （例如 <code class="docutils literal notranslate"><span class="pre">12/31/2003</span> <span class="pre">4</span> <span class="pre">p.m.</span></code>）</p>
<p>可用于在模板上显示日期时间字段的可用格式。请注意，如果 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 被设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，那么相应的本地决定的格式具有更高的优先级，并将被应用。参见 <a class="reference internal" href="templates/builtins.html#std:templatefilter-date"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">允许的日期格式字符串</span></code></a>。</p>
<p>另见 <a class="reference internal" href="#std:setting-DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_FORMAT</span></code></a> 和 <a class="reference internal" href="#std:setting-SHORT_DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SHORT_DATE_FORMAT</span></code></a>。</p>
</div>
<div class="section" id="s-signing-backend">
<span id="s-std:setting-SIGNING_BACKEND"></span><span id="signing-backend"></span><span id="std:setting-SIGNING_BACKEND"></span><h3><code class="docutils literal notranslate"><span class="pre">SIGNING_BACKEND</span></code><a class="headerlink" href="#signing-backend" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'django.core.signing.TimestampSigner'</span></code></p>
<p>用于签署 cookie 和其他数据的后端。</p>
<p>另见 <a class="reference internal" href="../topics/signing.html"><span class="doc">加密签名</span></a> 文档。</p>
</div>
<div class="section" id="s-silenced-system-checks">
<span id="s-std:setting-SILENCED_SYSTEM_CHECKS"></span><span id="silenced-system-checks"></span><span id="std:setting-SILENCED_SYSTEM_CHECKS"></span><h3><code class="docutils literal notranslate"><span class="pre">SILENCED_SYSTEM_CHECKS</span></code><a class="headerlink" href="#silenced-system-checks" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>你希望永久获取和忽略的系统检查框架生成的消息标识符列表（即 <code class="docutils literal notranslate"><span class="pre">[&quot;models.W001&quot;]</span></code>）。静默检查不会被输出到控制台。</p>
<p>另见 <a class="reference internal" href="checks.html"><span class="doc">系统检查框架</span></a> 文档。</p>
</div>
<div class="section" id="s-templates">
<span id="s-std:setting-TEMPLATES"></span><span id="templates"></span><span id="std:setting-TEMPLATES"></span><h3><code class="docutils literal notranslate"><span class="pre">TEMPLATES</span></code><a class="headerlink" href="#templates" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>一个包含所有 Django 模板引擎的配置的列表。列表中的每一项都是一个字典，包含了各个引擎的选项。</p>
<p>下面是一个配置，告诉 Django 模板引擎从每个安装好的应用程序中的 <code class="docutils literal notranslate"><span class="pre">templates</span></code> 子目录中加载模板：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">TEMPLATES</span> <span class="o">=</span> <span class="p">[</span>
    <span class="p">{</span>
        <span class="s1">&#39;BACKEND&#39;</span><span class="p">:</span> <span class="s1">&#39;django.template.backends.django.DjangoTemplates&#39;</span><span class="p">,</span>
        <span class="s1">&#39;APP_DIRS&#39;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
    <span class="p">},</span>
<span class="p">]</span>
</pre></div>
</div>
<p>以下选项适用于所有后端。</p>
<div class="section" id="s-std:setting-TEMPLATES-BACKEND">
<span id="s-id6"></span><span id="std:setting-TEMPLATES-BACKEND"></span><span id="id6"></span><h4><code class="docutils literal notranslate"><span class="pre">BACKEND</span></code><a class="headerlink" href="#std:setting-TEMPLATES-BACKEND" title="永久链接至标题">¶</a></h4>
<p>默认：未定义</p>
<p>要使用的模板后端。内置的模板后端有：</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">'django.template.backends.django.DjangoTemplates'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.template.backends.jinja2.Jinja2'</span></code></li>
</ul>
<p>你可以通过将 <code class="docutils literal notranslate"><span class="pre">BACKEND</span></code> 设置为一个完全限定的路径（例如 <code class="docutils literal notranslate"><span class="pre">'mypackage.whatever.Backend'</span></code>）来使用一个不在 Django 中的模板后端。</p>
</div>
<div class="section" id="s-std:setting-TEMPLATES-NAME">
<span id="s-id7"></span><span id="std:setting-TEMPLATES-NAME"></span><span id="id7"></span><h4><code class="docutils literal notranslate"><span class="pre">NAME</span></code><a class="headerlink" href="#std:setting-TEMPLATES-NAME" title="永久链接至标题">¶</a></h4>
<p>默认：见下方</p>
<p>这个特定模板引擎的别称。它是一个标识符，允许选择一个引擎进行渲染。所有配置的模板引擎的别名必须是唯一的。</p>
<p>它默认为定义引擎类的模块名称，即 <a class="reference internal" href="#std:setting-TEMPLATES-BACKEND"><code class="xref std std-setting docutils literal notranslate"><span class="pre">BACKEND</span></code></a> 的下一个到最后一个，如果没有提供的话。例如，如果后端是 <code class="docutils literal notranslate"><span class="pre">'mypackage.whatever.Backend'</span></code>，那么它的默认名称是 <code class="docutils literal notranslate"><span class="pre">'whatever'</span></code>。</p>
</div>
<div class="section" id="s-dirs">
<span id="s-std:setting-TEMPLATES-DIRS"></span><span id="dirs"></span><span id="std:setting-TEMPLATES-DIRS"></span><h4><code class="docutils literal notranslate"><span class="pre">DIRS</span></code><a class="headerlink" href="#dirs" title="永久链接至标题">¶</a></h4>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>按照搜索顺序，引擎应该查找模板源文件的目录。</p>
</div>
<div class="section" id="s-app-dirs">
<span id="s-std:setting-TEMPLATES-APP_DIRS"></span><span id="app-dirs"></span><span id="std:setting-TEMPLATES-APP_DIRS"></span><h4><code class="docutils literal notranslate"><span class="pre">APP_DIRS</span></code><a class="headerlink" href="#app-dirs" title="永久链接至标题">¶</a></h4>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>引擎是否应该在已安装的应用程序中查找模板源文件。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">默认的 <code class="file docutils literal notranslate"><span class="pre">settings.py</span></code> 文件由 <a class="reference internal" href="django-admin.html#django-admin-startproject"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">django-admin</span> <span class="pre">startproject</span></code></a> 创建，设置 <code class="docutils literal notranslate"><span class="pre">'APP_DIRS':</span> <span class="pre">True</span></code>。</p>
</div>
</div>
<div class="section" id="s-std:setting-TEMPLATES-OPTIONS">
<span id="s-id8"></span><span id="std:setting-TEMPLATES-OPTIONS"></span><span id="id8"></span><h4><code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code><a class="headerlink" href="#std:setting-TEMPLATES-OPTIONS" title="永久链接至标题">¶</a></h4>
<p>默认值： <code class="docutils literal notranslate"><span class="pre">{}</span></code> （空字典）</p>
<p>要传递给模板后台的额外参数。根据模板后端的不同，可用的参数也不同。参见 <a class="reference internal" href="../topics/templates.html#django.template.backends.django.DjangoTemplates" title="django.template.backends.django.DjangoTemplates"><code class="xref py py-class docutils literal notranslate"><span class="pre">DjangoTemplates</span></code></a> 和 <a class="reference internal" href="../topics/templates.html#django.template.backends.jinja2.Jinja2" title="django.template.backends.jinja2.Jinja2"><code class="xref py py-class docutils literal notranslate"><span class="pre">Jinja2</span></code></a> 了解内置后端的选项。</p>
</div>
</div>
<div class="section" id="s-test-runner">
<span id="s-std:setting-TEST_RUNNER"></span><span id="test-runner"></span><span id="std:setting-TEST_RUNNER"></span><h3><code class="docutils literal notranslate"><span class="pre">TEST_RUNNER</span></code><a class="headerlink" href="#test-runner" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'django.test.runner.DiscoverRunner'</span></code></p>
<p>用于启动测试套件的类的名称。参见 <a class="reference internal" href="../topics/testing/advanced.html#other-testing-frameworks"><span class="std std-ref">使用不同的测试框架</span></a>。</p>
</div>
<div class="section" id="s-test-non-serialized-apps">
<span id="s-std:setting-TEST_NON_SERIALIZED_APPS"></span><span id="test-non-serialized-apps"></span><span id="std:setting-TEST_NON_SERIALIZED_APPS"></span><h3><code class="docutils literal notranslate"><span class="pre">TEST_NON_SERIALIZED_APPS</span></code><a class="headerlink" href="#test-non-serialized-apps" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>为了在 <code class="docutils literal notranslate"><span class="pre">TransactionTestCase</span></code> 和没有事务的数据库后端测试之间恢复数据库状态，Django 在启动测试运行时，会 <a class="reference internal" href="../topics/testing/overview.html#test-case-serialized-rollback"><span class="std std-ref">序列化所有应用的内容</span></a>，这样就可以在运行需要的测试之前，从该副本重新加载。</p>
<p>这将减慢测试运行器的启动时间；如果你有一些应用程序不需要这个功能，你可以在这里添加它们的全名（例如 <code class="docutils literal notranslate"><span class="pre">'django.contrib.contenttypes'</span></code>），将它们从这个序列化过程中排除。</p>
</div>
<div class="section" id="s-thousand-separator">
<span id="s-std:setting-THOUSAND_SEPARATOR"></span><span id="thousand-separator"></span><span id="std:setting-THOUSAND_SEPARATOR"></span><h3><code class="docutils literal notranslate"><span class="pre">THOUSAND_SEPARATOR</span></code><a class="headerlink" href="#thousand-separator" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">','</span></code> （英文逗号）</p>
<p>格式化数字时使用的默认千位分隔符。只有当 <a class="reference internal" href="#std:setting-USE_THOUSAND_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_THOUSAND_SEPARATOR</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 和 <a class="reference internal" href="#std:setting-NUMBER_GROUPING"><code class="xref std std-setting docutils literal notranslate"><span class="pre">NUMBER_GROUPING</span></code></a> 大于 <code class="docutils literal notranslate"><span class="pre">0</span></code> 时，才使用此配置。</p>
<p>请注意，如果 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，那么将采用本地决定的格式，具有更高的优先权。</p>
<p>另见 <a class="reference internal" href="#std:setting-NUMBER_GROUPING"><code class="xref std std-setting docutils literal notranslate"><span class="pre">NUMBER_GROUPING</span></code></a>、<a class="reference internal" href="#std:setting-DECIMAL_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DECIMAL_SEPARATOR</span></code></a> 和 <a class="reference internal" href="#std:setting-USE_THOUSAND_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_THOUSAND_SEPARATOR</span></code></a>。</p>
</div>
<div class="section" id="s-time-format">
<span id="s-std:setting-TIME_FORMAT"></span><span id="time-format"></span><span id="std:setting-TIME_FORMAT"></span><h3><code class="docutils literal notranslate"><span class="pre">TIME_FORMAT</span></code><a class="headerlink" href="#time-format" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'P'</span></code> （例如 <code class="docutils literal notranslate"><span class="pre">4</span> <span class="pre">p.m.</span></code>）</p>
<p>在系统的任何部分显示时间字段时使用的默认格式。请注意，如果 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 被设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，那么本地决定的格式具有更高的优先权，并将被应用。参见 <a class="reference internal" href="templates/builtins.html#std:templatefilter-date"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">允许的日期格式字符串</span></code></a>。</p>
<p>另见 <a class="reference internal" href="#std:setting-DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_FORMAT</span></code></a> 和 <a class="reference internal" href="#std:setting-DATETIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATETIME_FORMAT</span></code></a>。</p>
</div>
<div class="section" id="s-time-input-formats">
<span id="s-std:setting-TIME_INPUT_FORMATS"></span><span id="time-input-formats"></span><span id="std:setting-TIME_INPUT_FORMATS"></span><h3><code class="docutils literal notranslate"><span class="pre">TIME_INPUT_FORMATS</span></code><a class="headerlink" href="#time-input-formats" title="永久链接至标题">¶</a></h3>
<p>默认：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
    <span class="s1">&#39;%H:%M:%S&#39;</span><span class="p">,</span>     <span class="c1"># &#39;14:30:59&#39;</span>
    <span class="s1">&#39;%H:%M:%S.</span><span class="si">%f</span><span class="s1">&#39;</span><span class="p">,</span>  <span class="c1"># &#39;14:30:59.000200&#39;</span>
    <span class="s1">&#39;%H:%M&#39;</span><span class="p">,</span>        <span class="c1"># &#39;14:30&#39;</span>
<span class="p">]</span>
</pre></div>
</div>
<p>在时间字段上输入数据时可接受的格式列表。格式将按顺序被尝试，使用第一个有效的格式。注意这些格式字符串使用 Python 的 <a class="reference external" href="https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior" title="(在 Python v3.10)"><span class="xref std std-ref">datetime 模块语法</span></a>，而不是来自 <a class="reference internal" href="templates/builtins.html#std:templatefilter-date"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">date</span></code></a> 模板过滤器的格式字符串。</p>
<p>当 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 时，将采用本地规定的格式，具有更高的优先权。</p>
<p>另见 <a class="reference internal" href="#std:setting-DATE_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_INPUT_FORMATS</span></code></a> 和 <a class="reference internal" href="#std:setting-DATETIME_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATETIME_INPUT_FORMATS</span></code></a>。</p>
</div>
<div class="section" id="s-std:setting-TIME_ZONE">
<span id="s-id9"></span><span id="std:setting-TIME_ZONE"></span><span id="id9"></span><h3><code class="docutils literal notranslate"><span class="pre">TIME_ZONE</span></code><a class="headerlink" href="#std:setting-TIME_ZONE" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'America/Chicago'</span></code></p>
<p>表示本次安装的时区的字符串。参见 <a class="reference external" href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones">时区列表</a> 。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">自从 Django 首次发布时， <a class="reference internal" href="#std:setting-TIME_ZONE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_ZONE</span></code></a> 设置为 <code class="docutils literal notranslate"><span class="pre">'America/Chicago'</span></code>，为了向后兼容，全局配置（如果你的项目 <code class="docutils literal notranslate"><span class="pre">settings.py</span></code> 中没有定义任何内容，则使用全局配置）仍为 <code class="docutils literal notranslate"><span class="pre">'America/Chicago'</span></code>。新项目模板默认为 <code class="docutils literal notranslate"><span class="pre">'UTC'</span></code>。</p>
</div>
<p>注意，这不一定是服务器的时区。例如，一个服务器可能服务于多个 Django 网站，每个网站都有单独的时区配置。</p>
<p>当 <a class="reference internal" href="#std:setting-USE_TZ"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_TZ</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code> 时，这是 Django 存储所有日期时间的时区。当 <a class="reference internal" href="#std:setting-USE_TZ"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_TZ</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 时，这是 Django 在模板中显示日期时间和解释表单中输入的日期时间的默认时区。</p>
<p>在 Unix 环境下（实现了 <a class="reference external" href="https://docs.python.org/3/library/time.html#time.tzset" title="(在 Python v3.10)"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.tzset()</span></code></a>），Django 将 <code class="docutils literal notranslate"><span class="pre">os.environ['TZ']</span></code> 变量设置为你在 <a class="reference internal" href="#std:setting-TIME_ZONE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_ZONE</span></code></a> 配置中指定的时区。这样，你所有的视图和模型都会自动在这个时区运行。但是，如果你使用的是 <a class="reference internal" href="../topics/settings.html#settings-without-django-settings-module"><span class="std std-ref">手动设置配置</span></a> 中描述的手动配置选项，Django 就不会设置 <code class="docutils literal notranslate"><span class="pre">TZ</span></code> 环境变量。如果 Django 没有设置 <code class="docutils literal notranslate"><span class="pre">TZ</span></code> 环境变量，那么就需要你确保你的进程运行在正确的环境中。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">Django 无法在 Windows 环境下可靠地使用交替时区。如果你在 Windows 上运行 Django， <a class="reference internal" href="#std:setting-TIME_ZONE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_ZONE</span></code></a> 必须设置为与系统时区匹配。</p>
</div>
</div>
<div class="section" id="s-use-i18n">
<span id="s-std:setting-USE_I18N"></span><span id="use-i18n"></span><span id="std:setting-USE_I18N"></span><h3><code class="docutils literal notranslate"><span class="pre">USE_I18N</span></code><a class="headerlink" href="#use-i18n" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">True</span></code></p>
<p>一个布尔值，用于指定是否应该启用 Django 的翻译系统。这提供了一个关闭翻译系统的方法，以保证性能。如果设置为 <code class="docutils literal notranslate"><span class="pre">False</span></code>，Django 会进行一些优化，以避免加载翻译机制。</p>
<p>另见 <code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_CODE'、</span> <span class="pre">:setting:`USE_L10N</span></code> 和 :setting:<a href="#id1"><span class="problematic" id="id2">`</span></a>USE_TZ'。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">默认的 <code class="file docutils literal notranslate"><span class="pre">settings.py</span></code> 文件由 <a class="reference internal" href="django-admin.html#django-admin-startproject"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">django-admin</span> <span class="pre">startproject</span></code></a> 创建，包括方便起见 <code class="docutils literal notranslate"><span class="pre">USE_I18N</span> <span class="pre">=</span> <span class="pre">True</span></code>。</p>
</div>
</div>
<div class="section" id="s-use-l10n">
<span id="s-std:setting-USE_L10N"></span><span id="use-l10n"></span><span id="std:setting-USE_L10N"></span><h3><code class="docutils literal notranslate"><span class="pre">USE_L10N</span></code><a class="headerlink" href="#use-l10n" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>一个布尔值，用于指定是否默认启用数据的本地化格式。如果设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，例如，Django 将使用当前语言的格式来显示数字和日期。</p>
<p>另见 <a class="reference internal" href="#std:setting-LANGUAGE_CODE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_CODE</span></code></a>、<a class="reference internal" href="#std:setting-USE_I18N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_I18N</span></code></a> 和 <a class="reference internal" href="#std:setting-USE_TZ"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_TZ</span></code></a>。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">默认的 <code class="file docutils literal notranslate"><span class="pre">settings.py</span></code> 文件由 <a class="reference internal" href="django-admin.html#django-admin-startproject"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">django-admin</span> <span class="pre">startproject</span></code></a> 创建，包括方便起见 <code class="docutils literal notranslate"><span class="pre">USE_L10N</span> <span class="pre">=</span> <span class="pre">True</span></code>。</p>
</div>
</div>
<div class="section" id="s-use-thousand-separator">
<span id="s-std:setting-USE_THOUSAND_SEPARATOR"></span><span id="use-thousand-separator"></span><span id="std:setting-USE_THOUSAND_SEPARATOR"></span><h3><code class="docutils literal notranslate"><span class="pre">USE_THOUSAND_SEPARATOR</span></code><a class="headerlink" href="#use-thousand-separator" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>一个布尔值，用于指定是否使用千位分隔符显示数字。当设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 且 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 也为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 时，Django 将使用 <a class="reference internal" href="#std:setting-NUMBER_GROUPING"><code class="xref std std-setting docutils literal notranslate"><span class="pre">NUMBER_GROUPING</span></code></a> 和 <a class="reference internal" href="#std:setting-THOUSAND_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">THOUSAND_SEPARATOR</span></code></a> 配置来格式化数字。这些配置也可能由 locale 决定，以 locale 为准。</p>
<p>另见 <a class="reference internal" href="#std:setting-DECIMAL_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DECIMAL_SEPARATOR</span></code></a>、<a class="reference internal" href="#std:setting-NUMBER_GROUPING"><code class="xref std std-setting docutils literal notranslate"><span class="pre">NUMBER_GROUPING</span></code></a> 和 <a class="reference internal" href="#std:setting-THOUSAND_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">THOUSAND_SEPARATOR</span></code></a>。</p>
</div>
<div class="section" id="s-use-tz">
<span id="s-std:setting-USE_TZ"></span><span id="use-tz"></span><span id="std:setting-USE_TZ"></span><h3><code class="docutils literal notranslate"><span class="pre">USE_TZ</span></code><a class="headerlink" href="#use-tz" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>一个布尔值，用于指定 Django 是否默认使用时区感知。如果设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，Django 将在内部使用时区感知的日期。</p>
<p>当 <code class="docutils literal notranslate"><span class="pre">USE_TZ</span></code> 为 False 时，Django 将使用本地时间的本地日期，除非在解析 ISO 8601 格式的字符串时，如果存在时区信息，则会一直保留。</p>
<p>另见 <a class="reference internal" href="#std:setting-TIME_ZONE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_ZONE</span></code></a>、<a class="reference internal" href="#std:setting-USE_I18N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_I18N</span></code></a> 和 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a>。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">默认的 <code class="file docutils literal notranslate"><span class="pre">settings.py</span></code> 文件由 <a class="reference internal" href="django-admin.html#django-admin-startproject"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">django-admin</span> <span class="pre">startproject</span></code></a> 创建，包括方便起见 <code class="docutils literal notranslate"><span class="pre">USE_TZ</span> <span class="pre">=</span> <span class="pre">True</span></code>。</p>
</div>
</div>
<div class="section" id="s-use-x-forwarded-host">
<span id="s-std:setting-USE_X_FORWARDED_HOST"></span><span id="use-x-forwarded-host"></span><span id="std:setting-USE_X_FORWARDED_HOST"></span><h3><code class="docutils literal notranslate"><span class="pre">USE_X_FORWARDED_HOST</span></code><a class="headerlink" href="#use-x-forwarded-host" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>一个布尔值，用于指定是否使用 <code class="docutils literal notranslate"><span class="pre">X-Forwarded-Host</span></code> 头，而不是 <code class="docutils literal notranslate"><span class="pre">Host</span></code> 头。只有在使用设置该头的代理时才应启用。</p>
<p>此设置优先于 <a class="reference internal" href="#std:setting-USE_X_FORWARDED_PORT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_X_FORWARDED_PORT</span></code></a>。根据 <span class="target" id="index-4"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc7239.html#section-5.3"><strong>RFC 7239#section-5.3</strong></a>，<code class="docutils literal notranslate"><span class="pre">X-Forwarded-Host</span></code> 头可以包括端口号，在这种情况下，你不应该使用 <a class="reference internal" href="#std:setting-USE_X_FORWARDED_PORT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_X_FORWARDED_PORT</span></code></a>。</p>
</div>
<div class="section" id="s-use-x-forwarded-port">
<span id="s-std:setting-USE_X_FORWARDED_PORT"></span><span id="use-x-forwarded-port"></span><span id="std:setting-USE_X_FORWARDED_PORT"></span><h3><code class="docutils literal notranslate"><span class="pre">USE_X_FORWARDED_PORT</span></code><a class="headerlink" href="#use-x-forwarded-port" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>一个布尔值，用于指定是否使用 <code class="docutils literal notranslate"><span class="pre">X-Forwarded-Port</span></code> 头，而不是 <code class="docutils literal notranslate"><span class="pre">SERVER_PORT``META</span></code> 变量。只有在使用设置该头的代理时，才应启用。</p>
<p><a class="reference internal" href="#std:setting-USE_X_FORWARDED_HOST"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_X_FORWARDED_HOST</span></code></a> 优先于此配置。</p>
</div>
<div class="section" id="s-wsgi-application">
<span id="s-std:setting-WSGI_APPLICATION"></span><span id="wsgi-application"></span><span id="std:setting-WSGI_APPLICATION"></span><h3><code class="docutils literal notranslate"><span class="pre">WSGI_APPLICATION</span></code><a class="headerlink" href="#wsgi-application" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>Django 内置服务器（如 <a class="reference internal" href="django-admin.html#django-admin-runserver"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">runserver</span></code></a>）将使用的 WSGI 应用对象的完整 Python 路径。<a class="reference internal" href="django-admin.html#django-admin-startproject"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">django-admin</span> <span class="pre">startproject</span></code></a> 管理命令将创建一个标准的 <code class="docutils literal notranslate"><span class="pre">wsgi.py</span></code> 文件，其中有一个 <code class="docutils literal notranslate"><span class="pre">application</span></code> 可调用，并将此配置指向该 <code class="docutils literal notranslate"><span class="pre">application</span></code>。</p>
<p>如果没有设置，将使用 <code class="docutils literal notranslate"><span class="pre">django.core.wsgi.get_wsgi_application()</span></code> 的返回值。在这种情况下， <a class="reference internal" href="django-admin.html#django-admin-runserver"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">runserver</span></code></a> 的行为将与之前的 Django 版本相同。</p>
</div>
<div class="section" id="s-year-month-format">
<span id="s-std:setting-YEAR_MONTH_FORMAT"></span><span id="year-month-format"></span><span id="std:setting-YEAR_MONTH_FORMAT"></span><h3><code class="docutils literal notranslate"><span class="pre">YEAR_MONTH_FORMAT</span></code><a class="headerlink" href="#year-month-format" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'F</span> <span class="pre">Y'</span></code></p>
<p>在 Django admin change-list 页面中，当只显示年和月的时候，默认的日期字段的格式也可能被系统的其他部分使用。</p>
<p>例如，当 Django 管理员的变更列表页面被日期 drilldown 过滤时，给定月份的头显示月份和年份。不同的地域有不同的格式。例如，美国英语会说“January 2006”，而另一个地方语言可能会说 “2006/January”。</p>
<p>请注意，如果 <a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，则相应的本地决定的格式具有更高的优先权，并将被应用。</p>
<p>查看 <a class="reference internal" href="templates/builtins.html#std:templatefilter-date"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">允许的日期格式字符串</span></code></a>。另见 <a class="reference internal" href="#std:setting-DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_FORMAT</span></code></a>、<a class="reference internal" href="#std:setting-DATETIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATETIME_FORMAT</span></code></a>、<a class="reference internal" href="#std:setting-TIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_FORMAT</span></code></a> 和 <a class="reference internal" href="#std:setting-MONTH_DAY_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MONTH_DAY_FORMAT</span></code></a>。</p>
</div>
<div class="section" id="s-x-frame-options">
<span id="s-std:setting-X_FRAME_OPTIONS"></span><span id="x-frame-options"></span><span id="std:setting-X_FRAME_OPTIONS"></span><h3><code class="docutils literal notranslate"><span class="pre">X_FRAME_OPTIONS</span></code><a class="headerlink" href="#x-frame-options" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'DENY'</span></code></p>
<p><a class="reference internal" href="middleware.html#django.middleware.clickjacking.XFrameOptionsMiddleware" title="django.middleware.clickjacking.XFrameOptionsMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">XFrameOptionsMiddleware</span></code></a> 使用的 X- Frame-Options 头的默认值。参见 <a class="reference internal" href="clickjacking.html"><span class="doc">点击劫持保护</span></a> 文档。</p>
</div>
</div>
<div class="section" id="s-auth">
<span id="auth"></span><h2><a class="toc-backref" href="#id13">认证</a><a class="headerlink" href="#auth" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="../topics/auth/index.html#module-django.contrib.auth" title="django.contrib.auth: Django's authentication framework."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.auth</span></code></a> 的配置。</p>
<div class="section" id="s-authentication-backends">
<span id="s-std:setting-AUTHENTICATION_BACKENDS"></span><span id="authentication-backends"></span><span id="std:setting-AUTHENTICATION_BACKENDS"></span><h3><code class="docutils literal notranslate"><span class="pre">AUTHENTICATION_BACKENDS</span></code><a class="headerlink" href="#authentication-backends" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">['django.contrib.auth.backends.ModelBackend']</span></code></p>
<p>当试图认证用户时，要使用的认证后端类（字符串）列表。详情请参见 <a class="reference internal" href="../topics/auth/customizing.html#authentication-backends"><span class="std std-ref">认证后端文档</span></a>。</p>
</div>
<div class="section" id="s-auth-user-model">
<span id="s-std:setting-AUTH_USER_MODEL"></span><span id="auth-user-model"></span><span id="std:setting-AUTH_USER_MODEL"></span><h3><code class="docutils literal notranslate"><span class="pre">AUTH_USER_MODEL</span></code><a class="headerlink" href="#auth-user-model" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'auth.User'</span></code></p>
<p>用来表示用户的模型。见 <a class="reference internal" href="../topics/auth/customizing.html#auth-custom-user"><span class="std std-ref">替换一个自定义的 User 模型。</span></a>。</p>
<div class="admonition warning">
<p class="first admonition-title">警告</p>
<p class="last">在项目的生命周期内（即一旦你制作并迁移了依赖它的模型），你无法不费吹灰之力地更改 AUTH_USER_MODEL 配置。它的目的是在项目开始时设置，并且它所引用的模型必须在它所在的应用程序的第一次迁移中可用。详见 <a class="reference internal" href="../topics/auth/customizing.html#auth-custom-user"><span class="std std-ref">替换一个自定义的 User 模型。</span></a>。</p>
</div>
</div>
<div class="section" id="s-login-redirect-url">
<span id="s-std:setting-LOGIN_REDIRECT_URL"></span><span id="login-redirect-url"></span><span id="std:setting-LOGIN_REDIRECT_URL"></span><h3><code class="docutils literal notranslate"><span class="pre">LOGIN_REDIRECT_URL</span></code><a class="headerlink" href="#login-redirect-url" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'/accounts/profile/'</span></code></p>
<p>当 <a class="reference internal" href="../topics/auth/default.html#django.contrib.auth.views.LoginView" title="django.contrib.auth.views.LoginView"><code class="xref py py-class docutils literal notranslate"><span class="pre">LoginView</span></code></a> 没有得到 <code class="docutils literal notranslate"><span class="pre">next</span></code> GET 参数时，登录后请求被重定向的 URL 或 <a class="reference internal" href="../topics/http/urls.html#naming-url-patterns"><span class="std std-ref">命名 URL 模式</span></a>。</p>
</div>
<div class="section" id="s-login-url">
<span id="s-std:setting-LOGIN_URL"></span><span id="login-url"></span><span id="std:setting-LOGIN_URL"></span><h3><code class="docutils literal notranslate"><span class="pre">LOGIN_URL</span></code><a class="headerlink" href="#login-url" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'/accounts/login/'</span></code></p>
<p>当使用 <a class="reference internal" href="../topics/auth/default.html#django.contrib.auth.decorators.login_required" title="django.contrib.auth.decorators.login_required"><code class="xref py py-func docutils literal notranslate"><span class="pre">login_required()</span></code></a> 装饰器、<a class="reference internal" href="../topics/auth/default.html#django.contrib.auth.mixins.LoginRequiredMixin" title="django.contrib.auth.mixins.LoginRequiredMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">LoginRequiredMixin</span></code></a> 或 <a class="reference internal" href="../topics/auth/default.html#django.contrib.auth.mixins.AccessMixin" title="django.contrib.auth.mixins.AccessMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">AccessMixin</span></code></a> 时，重定向请求登录的 URL 或 <a class="reference internal" href="../topics/http/urls.html#naming-url-patterns"><span class="std std-ref">命名 URL 模式</span></a>。</p>
</div>
<div class="section" id="s-logout-redirect-url">
<span id="s-std:setting-LOGOUT_REDIRECT_URL"></span><span id="logout-redirect-url"></span><span id="std:setting-LOGOUT_REDIRECT_URL"></span><h3><code class="docutils literal notranslate"><span class="pre">LOGOUT_REDIRECT_URL</span></code><a class="headerlink" href="#logout-redirect-url" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>如果 <a class="reference internal" href="../topics/auth/default.html#django.contrib.auth.views.LogoutView" title="django.contrib.auth.views.LogoutView"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogoutView</span></code></a> 没有 <code class="docutils literal notranslate"><span class="pre">next_page</span></code> 属性，则注销后重定向请求的 URL 或 <a class="reference internal" href="../topics/http/urls.html#naming-url-patterns"><span class="std std-ref">命名 URL 模式</span></a>。</p>
<p>如果 <code class="docutils literal notranslate"><span class="pre">None</span></code>，将不执行重定向，并显示注销视图。</p>
</div>
<div class="section" id="s-password-reset-timeout">
<span id="s-std:setting-PASSWORD_RESET_TIMEOUT"></span><span id="password-reset-timeout"></span><span id="std:setting-PASSWORD_RESET_TIMEOUT"></span><h3><code class="docutils literal notranslate"><span class="pre">PASSWORD_RESET_TIMEOUT</span></code><a class="headerlink" href="#password-reset-timeout" title="永久链接至标题">¶</a></h3>
<div class="versionadded">
<span class="title">New in Django 3.1.</span> </div>
<p>默认： <code class="docutils literal notranslate"><span class="pre">259200</span></code> （3 天，以秒为单位）</p>
<p>密码重置链接的有效秒数。</p>
<p>由 <a class="reference internal" href="../topics/auth/default.html#django.contrib.auth.views.PasswordResetConfirmView" title="django.contrib.auth.views.PasswordResetConfirmView"><code class="xref py py-class docutils literal notranslate"><span class="pre">PasswordResetConfirmView</span></code></a> 使用。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p>减少这个超时的值并不会对攻击者强行重置密码令牌的能力产生任何影响。令牌的设计是安全的，不需要任何超时。</p>
<p class="last">这个超时时间的存在，是为了防止一些不太可能发生的攻击情况，比如有人访问可能包含旧的、未使用的密码重置令牌的电子邮件档案。</p>
</div>
</div>
<div class="section" id="s-password-reset-timeout-days">
<span id="s-std:setting-PASSWORD_RESET_TIMEOUT_DAYS"></span><span id="password-reset-timeout-days"></span><span id="std:setting-PASSWORD_RESET_TIMEOUT_DAYS"></span><h3><code class="docutils literal notranslate"><span class="pre">PASSWORD_RESET_TIMEOUT_DAYS</span></code><a class="headerlink" href="#password-reset-timeout-days" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">3</span></code></p>
<p>密码重置链接的有效天数。</p>
<p>由 <a class="reference internal" href="../topics/auth/default.html#django.contrib.auth.views.PasswordResetConfirmView" title="django.contrib.auth.views.PasswordResetConfirmView"><code class="xref py py-class docutils literal notranslate"><span class="pre">PasswordResetConfirmView</span></code></a> 使用。</p>
<div class="deprecated">
<p><span class="versionmodified">3.1 版后已移除: </span>这个配置已被废弃了。使用 <a class="reference internal" href="#std:setting-PASSWORD_RESET_TIMEOUT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">PASSWORD_RESET_TIMEOUT</span></code></a> 代替。</p>
</div>
</div>
<div class="section" id="s-password-hashers">
<span id="s-std:setting-PASSWORD_HASHERS"></span><span id="password-hashers"></span><span id="std:setting-PASSWORD_HASHERS"></span><h3><code class="docutils literal notranslate"><span class="pre">PASSWORD_HASHERS</span></code><a class="headerlink" href="#password-hashers" title="永久链接至标题">¶</a></h3>
<p>查看 <a class="reference internal" href="../topics/auth/passwords.html#auth-password-storage"><span class="std std-ref">Django 如何存储密码</span></a>。</p>
<p>默认：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
    <span class="s1">&#39;django.contrib.auth.hashers.PBKDF2PasswordHasher&#39;</span><span class="p">,</span>
    <span class="s1">&#39;django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher&#39;</span><span class="p">,</span>
    <span class="s1">&#39;django.contrib.auth.hashers.Argon2PasswordHasher&#39;</span><span class="p">,</span>
    <span class="s1">&#39;django.contrib.auth.hashers.BCryptSHA256PasswordHasher&#39;</span><span class="p">,</span>
<span class="p">]</span>
</pre></div>
</div>
</div>
<div class="section" id="s-auth-password-validators">
<span id="s-std:setting-AUTH_PASSWORD_VALIDATORS"></span><span id="auth-password-validators"></span><span id="std:setting-AUTH_PASSWORD_VALIDATORS"></span><h3><code class="docutils literal notranslate"><span class="pre">AUTH_PASSWORD_VALIDATORS</span></code><a class="headerlink" href="#auth-password-validators" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>用于检查用户密码强度的验证器列表。更多细节请参见 <a class="reference internal" href="../topics/auth/passwords.html#password-validation"><span class="std std-ref">密码验证</span></a>。默认情况下，不执行验证，所有密码都被接受。</p>
</div>
</div>
<div class="section" id="s-messages">
<span id="s-settings-messages"></span><span id="messages"></span><span id="settings-messages"></span><h2><a class="toc-backref" href="#id14">消息</a><a class="headerlink" href="#messages" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="contrib/messages.html#module-django.contrib.messages" title="django.contrib.messages: Provides cookie- and session-based temporary message storage."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.messages</span></code></a> 的配置。</p>
<div class="section" id="s-message-level">
<span id="s-std:setting-MESSAGE_LEVEL"></span><span id="message-level"></span><span id="std:setting-MESSAGE_LEVEL"></span><h3><code class="docutils literal notranslate"><span class="pre">MESSAGE_LEVEL</span></code><a class="headerlink" href="#message-level" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">messages.INFO</span></code></p>
<p>设置消息框架将记录的最小消息级别。详见 <a class="reference internal" href="contrib/messages.html#message-level"><span class="std std-ref">消息级别</span></a>。</p>
<div class="admonition-important admonition">
<p class="first admonition-title">重要信息</p>
<p>如果你在配置文件中覆盖了 <code class="docutils literal notranslate"><span class="pre">MESSAGE_LEVEL</span></code>，并依赖任何内置的常量，你必须直接导入常量模块以避免循环导入的可能性，例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.contrib.messages</span> <span class="kn">import</span> <span class="n">constants</span> <span class="k">as</span> <span class="n">message_constants</span>
<span class="n">MESSAGE_LEVEL</span> <span class="o">=</span> <span class="n">message_constants</span><span class="o">.</span><span class="n">DEBUG</span>
</pre></div>
</div>
<p class="last">如果需要，可以直接根据上面 <a class="reference internal" href="contrib/messages.html#message-level-constants"><span class="std std-ref">常量表</span></a> 中的数值来指定常量的数值。</p>
</div>
</div>
<div class="section" id="s-message-storage">
<span id="s-std:setting-MESSAGE_STORAGE"></span><span id="message-storage"></span><span id="std:setting-MESSAGE_STORAGE"></span><h3><code class="docutils literal notranslate"><span class="pre">MESSAGE_STORAGE</span></code><a class="headerlink" href="#message-storage" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'django.contrib.messages.storage.fallback.FallbackStorage'</span></code></p>
<p>控制 Django 存储消息数据的地方。有效值是：</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">'django.contrib.messages.storage.fallback.FallbackStorage'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.contrib.messages.storage.session.SessionStorage'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.contrib.messages.storage.cookie.CookieStorage'</span></code></li>
</ul>
<p>详见 <a class="reference internal" href="contrib/messages.html#message-storage-backends"><span class="std std-ref">消息储存后端</span></a>。</p>
<p>使用 cookie 的后端—— <a class="reference internal" href="contrib/messages.html#django.contrib.messages.storage.cookie.CookieStorage" title="django.contrib.messages.storage.cookie.CookieStorage"><code class="xref py py-class docutils literal notranslate"><span class="pre">CookieStorage</span></code></a> 和 <a class="reference internal" href="contrib/messages.html#django.contrib.messages.storage.fallback.FallbackStorage" title="django.contrib.messages.storage.fallback.FallbackStorage"><code class="xref py py-class docutils literal notranslate"><span class="pre">FallbackStorage</span></code></a> ——在设置它们的 cookie 时，使用 <a class="reference internal" href="#std:setting-SESSION_COOKIE_DOMAIN"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SESSION_COOKIE_DOMAIN</span></code></a>、<a class="reference internal" href="#std:setting-SESSION_COOKIE_SECURE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SESSION_COOKIE_SECURE</span></code></a> 和 <a class="reference internal" href="#std:setting-SESSION_COOKIE_HTTPONLY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SESSION_COOKIE_HTTPONLY</span></code></a> 的值。</p>
</div>
<div class="section" id="s-message-tags">
<span id="s-std:setting-MESSAGE_TAGS"></span><span id="message-tags"></span><span id="std:setting-MESSAGE_TAGS"></span><h3><code class="docutils literal notranslate"><span class="pre">MESSAGE_TAGS</span></code><a class="headerlink" href="#message-tags" title="永久链接至标题">¶</a></h3>
<p>默认：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
    <span class="n">messages</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">:</span> <span class="s1">&#39;debug&#39;</span><span class="p">,</span>
    <span class="n">messages</span><span class="o">.</span><span class="n">INFO</span><span class="p">:</span> <span class="s1">&#39;info&#39;</span><span class="p">,</span>
    <span class="n">messages</span><span class="o">.</span><span class="n">SUCCESS</span><span class="p">:</span> <span class="s1">&#39;success&#39;</span><span class="p">,</span>
    <span class="n">messages</span><span class="o">.</span><span class="n">WARNING</span><span class="p">:</span> <span class="s1">&#39;warning&#39;</span><span class="p">,</span>
    <span class="n">messages</span><span class="o">.</span><span class="n">ERROR</span><span class="p">:</span> <span class="s1">&#39;error&#39;</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</div>
<p>这设置了消息级别到消息标签的映射，通常在 HTML 中以 CSS 类的形式呈现。如果你指定了一个值，它将扩展默认值。这意味着你只需要指定那些你需要覆盖的值。更多细节请参考上面的 <a class="reference internal" href="contrib/messages.html#message-displaying"><span class="std std-ref">显示消息</span></a>。</p>
<div class="admonition-important admonition">
<p class="first admonition-title">重要信息</p>
<p>如果你在配置文件中覆盖了 <code class="docutils literal notranslate"><span class="pre">MESSAGE_TAGS</span></code>，并依赖任何内置的常量，你必须直接导入 <code class="docutils literal notranslate"><span class="pre">constants</span></code> 模块，以避免循环导入的可能性，例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.contrib.messages</span> <span class="kn">import</span> <span class="n">constants</span> <span class="k">as</span> <span class="n">message_constants</span>
<span class="n">MESSAGE_TAGS</span> <span class="o">=</span> <span class="p">{</span><span class="n">message_constants</span><span class="o">.</span><span class="n">INFO</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">}</span>
</pre></div>
</div>
<p class="last">如果需要，可以直接根据上面 <a class="reference internal" href="contrib/messages.html#message-level-constants"><span class="std std-ref">常量表</span></a> 中的数值来指定常量的数值。</p>
</div>
</div>
</div>
<div class="section" id="s-sessions">
<span id="s-settings-sessions"></span><span id="sessions"></span><span id="settings-sessions"></span><h2><a class="toc-backref" href="#id15">会话</a><a class="headerlink" href="#sessions" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="../topics/http/sessions.html#module-django.contrib.sessions" title="django.contrib.sessions: Provides session management for Django projects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.sessions</span></code></a> 的配置。</p>
<div class="section" id="s-session-cache-alias">
<span id="s-std:setting-SESSION_CACHE_ALIAS"></span><span id="session-cache-alias"></span><span id="std:setting-SESSION_CACHE_ALIAS"></span><h3><code class="docutils literal notranslate"><span class="pre">SESSION_CACHE_ALIAS</span></code><a class="headerlink" href="#session-cache-alias" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'default'</span></code></p>
<p>如果你使用的是 <a class="reference internal" href="../topics/http/sessions.html#cached-sessions-backend"><span class="std std-ref">基于缓存的会话存储</span></a>，这将选择要使用的缓存。</p>
</div>
<div class="section" id="s-session-cookie-age">
<span id="s-std:setting-SESSION_COOKIE_AGE"></span><span id="session-cookie-age"></span><span id="std:setting-SESSION_COOKIE_AGE"></span><h3><code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_AGE</span></code><a class="headerlink" href="#session-cookie-age" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">1209600</span></code> （2 周，以秒为单位）</p>
<p>会话 cookie 的寿命，以秒为单位。</p>
</div>
<div class="section" id="s-session-cookie-domain">
<span id="s-std:setting-SESSION_COOKIE_DOMAIN"></span><span id="session-cookie-domain"></span><span id="std:setting-SESSION_COOKIE_DOMAIN"></span><h3><code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_DOMAIN</span></code><a class="headerlink" href="#session-cookie-domain" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>用于会话 cookie 的域。将其设置为一个字符串，如 <code class="docutils literal notranslate"><span class="pre">&quot;example.com&quot;</span></code>，用于跨域 cookie，或使用 <code class="docutils literal notranslate"><span class="pre">None</span></code> 用于标准域 cookie。</p>
<p>要使用带有 <a class="reference internal" href="#std:setting-CSRF_USE_SESSIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CSRF_USE_SESSIONS</span></code></a> 的跨域 cookie，你必须包括一个前导点（例如 <code class="docutils literal notranslate"><span class="pre">&quot;.example.com&quot;</span></code>），以适应 CSRF 中间件的引用检查。</p>
<p>在生产型网站上更新此配置时要谨慎。如果你更新此配置，在以前使用标准域 cookie 的网站上启用跨域 cookie，现有用户 cookie 将被设置为旧域。这可能导致他们无法登录，只要这些 cookie 持续存在。</p>
<p>这个配置也会影响到 <a class="reference internal" href="contrib/messages.html#module-django.contrib.messages" title="django.contrib.messages: Provides cookie- and session-based temporary message storage."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.messages</span></code></a> 所设置的 cookies。</p>
</div>
<div class="section" id="s-session-cookie-httponly">
<span id="s-std:setting-SESSION_COOKIE_HTTPONLY"></span><span id="session-cookie-httponly"></span><span id="std:setting-SESSION_COOKIE_HTTPONLY"></span><h3><code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_HTTPONLY</span></code><a class="headerlink" href="#session-cookie-httponly" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">True</span></code></p>
<p>是否对会话 cookie 使用 <code class="docutils literal notranslate"><span class="pre">HttpOnly</span></code> 标志。如果设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，客户端的 JavaScript 将无法访问会话 cookie。</p>
<p><a class="reference external" href="https://owasp.org/www-community/HttpOnly">HttpOnly</a> 是包含在 Set-Cookie HTTP 响应头中的一个标志。它是 <span class="target" id="index-5"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc6265.html#section-4.1.2.6"><strong>RFC 6265#section-4.1.2.6</strong></a> 标准中 Cookie 的一部分，可以作为一种有用的方式来降低客户端脚本访问受保护 Cookie 数据的风险。</p>
<p>这使得攻击者将跨站脚本漏洞升级为完全劫持用户的会话变得不那么简单。关闭这个功能的理由不多。你的代码不应该从 JavaScript 中读取会话 cookies。</p>
</div>
<div class="section" id="s-session-cookie-name">
<span id="s-std:setting-SESSION_COOKIE_NAME"></span><span id="session-cookie-name"></span><span id="std:setting-SESSION_COOKIE_NAME"></span><h3><code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_NAME</span></code><a class="headerlink" href="#session-cookie-name" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'sessionid'</span></code></p>
<p>用于会话的 cookie 的名称。这可以是任何你想要的（只要它与你的应用程序中的其他 cookie 名称不同）。</p>
</div>
<div class="section" id="s-session-cookie-path">
<span id="s-std:setting-SESSION_COOKIE_PATH"></span><span id="session-cookie-path"></span><span id="std:setting-SESSION_COOKIE_PATH"></span><h3><code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_PATH</span></code><a class="headerlink" href="#session-cookie-path" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'/'</span></code></p>
<p>会话 cookie 上设置的路径。这个路径应该与你的 Django 安装的 URL 路径相匹配，或者是该路径的父路径。</p>
<p>如果你有多个 Django 实例在同一个主机名下运行，这个功能很有用。他们可以使用不同的 cookie 路径，而且每个实例只能看到自己的会话 cookie。</p>
</div>
<div class="section" id="s-session-cookie-samesite">
<span id="s-std:setting-SESSION_COOKIE_SAMESITE"></span><span id="session-cookie-samesite"></span><span id="std:setting-SESSION_COOKIE_SAMESITE"></span><h3><code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_SAMESITE</span></code><a class="headerlink" href="#session-cookie-samesite" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'Lax'</span></code></p>
<p>会话 cookie 上的 <a class="reference external" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite">SameSite</a> 标志的值。这个标志可以防止 cookie 在跨站请求中被发送，从而防止 CSRF 攻击，使一些窃取会话 cookie 的方法变得不可能。</p>
<p>该配置的可能值为：</p>
<ul>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">'Strict'</span></code> ：防止浏览器在所有跨站点浏览的情况下向目标站点发送 cookie，即使在使用常规链接时也是如此。</p>
<p>例如，对于类似 GitHub 的网站来说，这意味着如果登录的用户通过企业论坛或电子邮件链接到 GitHub 的私人项目，GitHub 将不会收到会话 cookie，用户将无法访问该项目。然而，银行网站很可能不允许从外部网站链接任何交易页面，因此 <code class="docutils literal notranslate"><span class="pre">'Strict'</span></code> 标志将是合适的。</p>
</li>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">'Lax'</span></code> （默认）：为希望在用户从外部链接到达后保持用户登录会话的网站提供安全和可用性之间的平衡。</p>
<p>在 GitHub 的场景下，当跟随外部网站的常规链接时，会话 cookie 将被允许，而在 CSRF 倾向的请求方法（例如 <code class="docutils literal notranslate"><span class="pre">POST</span></code>）中被阻止。</p>
</li>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">'None'</span></code> （字符串）：会话 cookie 将随所有同站和跨站请求发送。</p>
</li>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">False</span></code> ：停用该标志。</p>
</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">现代浏览器为 <code class="docutils literal notranslate"><span class="pre">SameSite</span></code> 标志提供了一个更安全的默认策略，并将假定 <code class="docutils literal notranslate"><span class="pre">Lax</span></code> 为没有明确配置值的 cookies。</p>
</div>
<div class="versionchanged">
<span class="title">Changed in Django 3.1:</span> <p>允许设置 <code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_SAMESITE</span> <span class="pre">=</span> <span class="pre">'None'</span></code>。</p>
</div>
</div>
<div class="section" id="s-session-cookie-secure">
<span id="s-std:setting-SESSION_COOKIE_SECURE"></span><span id="session-cookie-secure"></span><span id="std:setting-SESSION_COOKIE_SECURE"></span><h3><code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_SECURE</span></code><a class="headerlink" href="#session-cookie-secure" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>是否对会话 cookie 使用安全 cookie。如果设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，cookie 将被标记为“安全”，这意味着浏览器可以确保 cookie 只在 HTTPS 连接下发送。</p>
<p>关闭这个配置并不是一个好主意，因为攻击者可以用数据包嗅探器捕获一个未加密的会话 cookie，并使用 cookie 来劫持用户的会话</p>
</div>
<div class="section" id="s-session-engine">
<span id="s-std:setting-SESSION_ENGINE"></span><span id="session-engine"></span><span id="std:setting-SESSION_ENGINE"></span><h3><code class="docutils literal notranslate"><span class="pre">SESSION_ENGINE</span></code><a class="headerlink" href="#session-engine" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'django.contrib.sessions.backends.db'</span></code></p>
<p>控制 Django 存储会话数据的地方。包括的引擎有：</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">'django.contrib.sessions.backends.db'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.contrib.sessions.backends.file'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.contrib.sessions.backends.cache'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.contrib.sessions.backends.cached_db'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.contrib.sessions.backends.signed_cookies'</span></code></li>
</ul>
<p>详见 <a class="reference internal" href="../topics/http/sessions.html#configuring-sessions"><span class="std std-ref">配置会话(session)引擎</span></a>。</p>
</div>
<div class="section" id="s-session-expire-at-browser-close">
<span id="s-std:setting-SESSION_EXPIRE_AT_BROWSER_CLOSE"></span><span id="session-expire-at-browser-close"></span><span id="std:setting-SESSION_EXPIRE_AT_BROWSER_CLOSE"></span><h3><code class="docutils literal notranslate"><span class="pre">SESSION_EXPIRE_AT_BROWSER_CLOSE</span></code><a class="headerlink" href="#session-expire-at-browser-close" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>是否在用户关闭浏览器时结束会话。参见 <a class="reference internal" href="../topics/http/sessions.html#browser-length-vs-persistent-sessions"><span class="std std-ref">Browser-length 会话 vs 持久会话</span></a>。</p>
</div>
<div class="section" id="s-session-file-path">
<span id="s-std:setting-SESSION_FILE_PATH"></span><span id="session-file-path"></span><span id="std:setting-SESSION_FILE_PATH"></span><h3><code class="docutils literal notranslate"><span class="pre">SESSION_FILE_PATH</span></code><a class="headerlink" href="#session-file-path" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>如果你使用的是基于文件的会话存储，那么这个选项设置了 Django 存储会话数据的目录，当使用默认值（<code class="docutils literal notranslate"><span class="pre">None</span></code>）时，Django 将使用系统的标准临时目录。</p>
</div>
<div class="section" id="s-session-save-every-request">
<span id="s-std:setting-SESSION_SAVE_EVERY_REQUEST"></span><span id="session-save-every-request"></span><span id="std:setting-SESSION_SAVE_EVERY_REQUEST"></span><h3><code class="docutils literal notranslate"><span class="pre">SESSION_SAVE_EVERY_REQUEST</span></code><a class="headerlink" href="#session-save-every-request" title="永久链接至标题">¶</a></h3>
<p>默认：<code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>是否在每次请求时保存会话数据。如果这个配置是 <code class="docutils literal notranslate"><span class="pre">False</span></code> （默认），那么会话数据只有在被修改时才会被保存，也就是说，如果它的任何字典值被分配或删除，那么会话数据就会被保存。即使这个配置是活动的，也不会创建空会话。</p>
</div>
<div class="section" id="s-session-serializer">
<span id="s-std:setting-SESSION_SERIALIZER"></span><span id="session-serializer"></span><span id="std:setting-SESSION_SERIALIZER"></span><h3><code class="docutils literal notranslate"><span class="pre">SESSION_SERIALIZER</span></code><a class="headerlink" href="#session-serializer" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'django.contrib.sessions.serializers.JSONSerializer'</span></code></p>
<p>用于序列化会话数据的序列化器类的完整导入路径。包括的序列化器有：</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">'django.contrib.sessions.serializers.PickleSerializer'</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">'django.contrib.sessions.serializers.JSONSerializer'</span></code></li>
</ul>
<p>参见 <a class="reference internal" href="../topics/http/sessions.html#session-serialization"><span class="std std-ref">会话序列化</span></a> 了解详情，包括当使用 <code class="xref py py-class docutils literal notranslate"><span class="pre">PickleSerializer</span></code> 时可能会出现远程代码执行的警告。</p>
</div>
</div>
<div class="section" id="s-sites">
<span id="sites"></span><h2><a class="toc-backref" href="#id16">站点</a><a class="headerlink" href="#sites" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="contrib/sites.html#module-django.contrib.sites" title="django.contrib.sites: Lets you operate multiple websites from the same database and Django project"><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.sites</span></code></a> 的配置。</p>
<div class="section" id="s-site-id">
<span id="s-std:setting-SITE_ID"></span><span id="site-id"></span><span id="std:setting-SITE_ID"></span><h3><code class="docutils literal notranslate"><span class="pre">SITE_ID</span></code><a class="headerlink" href="#site-id" title="永久链接至标题">¶</a></h3>
<p>默认：未定义</p>
<p>当前网站在 <code class="docutils literal notranslate"><span class="pre">django_site</span></code> 数据库表中的 ID，为整数。这样，应用数据就可以挂到特定的站点上，一个数据库可以管理多个站点的内容。</p>
</div>
</div>
<div class="section" id="s-static-files">
<span id="s-settings-staticfiles"></span><span id="static-files"></span><span id="settings-staticfiles"></span><h2><a class="toc-backref" href="#id17">静态文件</a><a class="headerlink" href="#static-files" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="contrib/staticfiles.html#module-django.contrib.staticfiles" title="django.contrib.staticfiles: An app for handling static files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.staticfiles</span></code></a> 的配置。</p>
<div class="section" id="s-static-root">
<span id="s-std:setting-STATIC_ROOT"></span><span id="static-root"></span><span id="std:setting-STATIC_ROOT"></span><h3><code class="docutils literal notranslate"><span class="pre">STATIC_ROOT</span></code><a class="headerlink" href="#static-root" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p><a class="reference internal" href="contrib/staticfiles.html#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a> 将收集静态文件进行部署的目录的绝对路径。</p>
<p>例如： <code class="docutils literal notranslate"><span class="pre">&quot;/var/www/example.com/static/&quot;</span></code></p>
<p>如果 <a class="reference internal" href="contrib/staticfiles.html"><span class="doc">staticfiles</span></a> contrib 应用已启用（如在默认的项目模板中）， <a class="reference internal" href="contrib/staticfiles.html#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a> 管理命令将收集静态文件到这个目录。更多使用方法请参见 <a class="reference internal" href="../howto/static-files/index.html"><span class="doc">管理静态文件</span></a> 的操作指南。</p>
<div class="admonition warning">
<p class="first admonition-title">警告</p>
<p class="last">这应该是一个初始为空的目标目录，用于将你的静态文件从其永久位置收集到一个目录中，以方便部署；它 <strong>不是</strong> 永久存储静态文件的地方。你应该在那些会被 <a class="reference internal" href="contrib/staticfiles.html"><span class="doc">静态文件</span></a> 的 <a class="reference internal" href="#std:setting-STATICFILES_FINDERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">finders</span></code></a> 找到的目录中进行，默认情况下，这些目录是 <code class="docutils literal notranslate"><span class="pre">'static/'</span></code> 应用子目录和你在 <a class="reference internal" href="#std:setting-STATICFILES_DIRS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_DIRS</span></code></a> 中包含的任何目录。</p>
</div>
</div>
<div class="section" id="s-static-url">
<span id="s-std:setting-STATIC_URL"></span><span id="static-url"></span><span id="std:setting-STATIC_URL"></span><h3><code class="docutils literal notranslate"><span class="pre">STATIC_URL</span></code><a class="headerlink" href="#static-url" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>引用位于 <a class="reference internal" href="#std:setting-STATIC_ROOT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_ROOT</span></code></a> 中的静态文件时要使用的 URL。</p>
<p>例如： <code class="docutils literal notranslate"><span class="pre">&quot;/static/&quot;</span></code> 或 <code class="docutils literal notranslate"><span class="pre">&quot;http://static.example.com/&quot;</span></code></p>
<p>如果不是 <code class="docutils literal notranslate"><span class="pre">None</span></code>，这将被用作 <a class="reference internal" href="../topics/forms/media.html#form-asset-paths"><span class="std std-ref">资源定义</span></a> （<code class="docutils literal notranslate"><span class="pre">Media</span></code> 类）和 <a class="reference internal" href="contrib/staticfiles.html"><span class="doc">静态文件应用</span></a> 的基本路径。</p>
<p>如果设置为非空值，必须以斜线结束。</p>
<p>你可能需要 <a class="reference internal" href="../howto/static-files/index.html#serving-static-files-in-development"><span class="std std-ref">在开发中服务这些文件</span></a>，在 <a class="reference internal" href="../howto/static-files/deployment.html"><span class="doc">生产中</span></a> 肯定需要这样做。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">如果 <a class="reference internal" href="#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a> 是一个相对路径，那么它将以服务器提供的 <code class="docutils literal notranslate"><span class="pre">SCRIPT_NAME</span></code> 的值为前缀（如果没有设置，则为 <code class="docutils literal notranslate"><span class="pre">/</span></code>）。这使得在子路径中服务 Django 应用时更容易，而无需在增加额外的配置。</p>
</div>
</div>
<div class="section" id="s-staticfiles-dirs">
<span id="s-std:setting-STATICFILES_DIRS"></span><span id="staticfiles-dirs"></span><span id="std:setting-STATICFILES_DIRS"></span><h3><code class="docutils literal notranslate"><span class="pre">STATICFILES_DIRS</span></code><a class="headerlink" href="#staticfiles-dirs" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">[]</span></code> （空列表）</p>
<p>这个配置定义了静态文件应用在启用 <code class="docutils literal notranslate"><span class="pre">FileSystemFinder</span></code> 查找器时将穿越的额外位置，例如，如果你使用 <a class="reference internal" href="contrib/staticfiles.html#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a> 或 <a class="reference internal" href="contrib/staticfiles.html#django-admin-findstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">findstatic</span></code></a> 管理命令或使用静态文件服务视图。</p>
<p>这应该被设置为包含附加文件目录完整路径的字符串列表，例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">STATICFILES_DIRS</span> <span class="o">=</span> <span class="p">[</span>
    <span class="s2">&quot;/home/special.polls.com/polls/static&quot;</span><span class="p">,</span>
    <span class="s2">&quot;/home/polls.com/polls/static&quot;</span><span class="p">,</span>
    <span class="s2">&quot;/opt/webfiles/common&quot;</span><span class="p">,</span>
<span class="p">]</span>
</pre></div>
</div>
<p>请注意，这些路径应该使用 Unix 风格的斜线，即使在 Windows 上也是如此（例如 <code class="docutils literal notranslate"><span class="pre">&quot;C:/Users/user/mysite/extra_static_content&quot;</span></code>）。</p>
<div class="section" id="s-prefixes-optional">
<span id="s-staticfiles-dirs-prefixes"></span><span id="prefixes-optional"></span><span id="staticfiles-dirs-prefixes"></span><h4>前缀（可选）<a class="headerlink" href="#prefixes-optional" title="永久链接至标题">¶</a></h4>
<p>如果你想用一个额外的命名空间来引用其中一个位置的文件，你可以 <strong>可选的</strong> 提供一个前缀作为 <code class="docutils literal notranslate"><span class="pre">(prefix,</span> <span class="pre">path)</span></code> 的元组，例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">STATICFILES_DIRS</span> <span class="o">=</span> <span class="p">[</span>
    <span class="c1"># ...</span>
    <span class="p">(</span><span class="s2">&quot;downloads&quot;</span><span class="p">,</span> <span class="s2">&quot;/opt/webfiles/stats&quot;</span><span class="p">),</span>
<span class="p">]</span>
</pre></div>
</div>
<p>例如，假设你将 <a class="reference internal" href="#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a> 设置为 <code class="docutils literal notranslate"><span class="pre">'/static/'</span></code>，则 <a class="reference internal" href="contrib/staticfiles.html#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a> 管理命令将收集 <a class="reference internal" href="#std:setting-STATIC_ROOT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_ROOT</span></code></a> 的 <code class="docutils literal notranslate"><span class="pre">'downloads'</span></code> 子目录中的“stats”文件。</p>
<p>这将允许你在你的模板中用 <code class="docutils literal notranslate"><span class="pre">'/static/downloads/polls_20101022.tar.gz'</span></code> 引用本地文件 <code class="docutils literal notranslate"><span class="pre">'/opt/webfiles/stats/polls_20101022.tar.gz'</span></code>，例如：</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">static</span> <span class="s1">&#39;downloads/polls_20101022.tar.gz&#39;</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="p">&gt;</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="s-staticfiles-storage">
<span id="s-std:setting-STATICFILES_STORAGE"></span><span id="staticfiles-storage"></span><span id="std:setting-STATICFILES_STORAGE"></span><h3><code class="docutils literal notranslate"><span class="pre">STATICFILES_STORAGE</span></code><a class="headerlink" href="#staticfiles-storage" title="永久链接至标题">¶</a></h3>
<p>默认： <code class="docutils literal notranslate"><span class="pre">'django.contrib.staticfiles.storage.StaticFilesStorage'</span></code></p>
<p>使用 <a class="reference internal" href="contrib/staticfiles.html#django-admin-collectstatic"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">collectstatic</span></code></a> 管理命令收集静态文件时要使用的文件存储引擎。</p>
<p>在此配置中定义的存储后端的即用实例可以在 <code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles.storage.staticfiles_storage</span></code> 中找到。</p>
<p>例如，参见 <a class="reference internal" href="../howto/static-files/deployment.html#staticfiles-from-cdn"><span class="std std-ref">从云服务或 CDN 提供静态文件服务</span></a>。</p>
</div>
<div class="section" id="s-staticfiles-finders">
<span id="s-std:setting-STATICFILES_FINDERS"></span><span id="staticfiles-finders"></span><span id="std:setting-STATICFILES_FINDERS"></span><h3><code class="docutils literal notranslate"><span class="pre">STATICFILES_FINDERS</span></code><a class="headerlink" href="#staticfiles-finders" title="永久链接至标题">¶</a></h3>
<p>默认：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
    <span class="s1">&#39;django.contrib.staticfiles.finders.FileSystemFinder&#39;</span><span class="p">,</span>
    <span class="s1">&#39;django.contrib.staticfiles.finders.AppDirectoriesFinder&#39;</span><span class="p">,</span>
<span class="p">]</span>
</pre></div>
</div>
<p>知道如何找到不同位置的静态文件的查找器后端列表。</p>
<p>默认情况下，将查找存储在 <a class="reference internal" href="#std:setting-STATICFILES_DIRS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_DIRS</span></code></a> 配置中的文件（使用 <code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles.finders.FileSystemFinder</span></code>）和每个应用程序的 <code class="docutils literal notranslate"><span class="pre">static</span></code> 子目录中的文件（使用 <code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles.finders.AppDirectoriesFinder</span></code>）。如果存在多个同名文件，将使用第一个找到的文件。</p>
<p>有一个查找器是默认禁用的： <code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles.finders.DefaultStorageFinder</span></code>。如果添加到你的 <a class="reference internal" href="#std:setting-STATICFILES_FINDERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_FINDERS</span></code></a> 配置中，它将在 <a class="reference internal" href="#std:setting-DEFAULT_FILE_STORAGE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_FILE_STORAGE</span></code></a> 配置所定义的默认文件存储中查找静态文件。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">当使用 <code class="docutils literal notranslate"><span class="pre">AppDirectoriesFinder</span></code> 查找器时，通过将应用添加到你的网站的 <a class="reference internal" href="#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a> 配置中，确保你的应用程序可以通过 staticfiles 找到。</p>
</div>
<p>静态文件查找器目前被认为是一个私有接口，因此这个接口是没有文档的。</p>
</div>
</div>
<div class="section" id="s-core-settings-topical-index">
<span id="core-settings-topical-index"></span><h2><a class="toc-backref" href="#id18">核心配置专题索引</a><a class="headerlink" href="#core-settings-topical-index" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-cache">
<span id="cache"></span><h3>缓存<a class="headerlink" href="#cache" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-CACHES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CACHES</span></code></a></li>
<li><a class="reference internal" href="#std:setting-CACHE_MIDDLEWARE_ALIAS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CACHE_MIDDLEWARE_ALIAS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-CACHE_MIDDLEWARE_KEY_PREFIX"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CACHE_MIDDLEWARE_KEY_PREFIX</span></code></a></li>
<li><a class="reference internal" href="#std:setting-CACHE_MIDDLEWARE_SECONDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CACHE_MIDDLEWARE_SECONDS</span></code></a></li>
</ul>
</div>
<div class="section" id="s-database">
<span id="database"></span><h3>数据库<a class="headerlink" href="#database" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-DATABASES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATABASES</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DATABASE_ROUTERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATABASE_ROUTERS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DEFAULT_INDEX_TABLESPACE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_INDEX_TABLESPACE</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DEFAULT_TABLESPACE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_TABLESPACE</span></code></a></li>
</ul>
</div>
<div class="section" id="s-debugging">
<span id="debugging"></span><h3>调试<a class="headerlink" href="#debugging" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DEBUG_PROPAGATE_EXCEPTIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG_PROPAGATE_EXCEPTIONS</span></code></a></li>
</ul>
</div>
<div class="section" id="s-email">
<span id="email"></span><h3>电子邮件<a class="headerlink" href="#email" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-ADMINS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">ADMINS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DEFAULT_CHARSET"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_CHARSET</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DEFAULT_FROM_EMAIL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_FROM_EMAIL</span></code></a></li>
<li><a class="reference internal" href="#std:setting-EMAIL_BACKEND"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_BACKEND</span></code></a></li>
<li><a class="reference internal" href="#std:setting-EMAIL_FILE_PATH"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_FILE_PATH</span></code></a></li>
<li><a class="reference internal" href="#std:setting-EMAIL_HOST"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_HOST</span></code></a></li>
<li><a class="reference internal" href="#std:setting-EMAIL_HOST_PASSWORD"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_HOST_PASSWORD</span></code></a></li>
<li><a class="reference internal" href="#std:setting-EMAIL_HOST_USER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_HOST_USER</span></code></a></li>
<li><a class="reference internal" href="#std:setting-EMAIL_PORT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_PORT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-EMAIL_SSL_CERTFILE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_SSL_CERTFILE</span></code></a></li>
<li><a class="reference internal" href="#std:setting-EMAIL_SSL_KEYFILE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_SSL_KEYFILE</span></code></a></li>
<li><a class="reference internal" href="#std:setting-EMAIL_SUBJECT_PREFIX"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_SUBJECT_PREFIX</span></code></a></li>
<li><a class="reference internal" href="#std:setting-EMAIL_TIMEOUT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_TIMEOUT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-EMAIL_USE_LOCALTIME"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_USE_LOCALTIME</span></code></a></li>
<li><a class="reference internal" href="#std:setting-EMAIL_USE_TLS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_USE_TLS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-MANAGERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MANAGERS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SERVER_EMAIL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SERVER_EMAIL</span></code></a></li>
</ul>
</div>
<div class="section" id="s-error-reporting">
<span id="error-reporting"></span><h3>发送错误<a class="headerlink" href="#error-reporting" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-DEFAULT_EXCEPTION_REPORTER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_EXCEPTION_REPORTER</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DEFAULT_EXCEPTION_REPORTER_FILTER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_EXCEPTION_REPORTER_FILTER</span></code></a></li>
<li><a class="reference internal" href="#std:setting-IGNORABLE_404_URLS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">IGNORABLE_404_URLS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-MANAGERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MANAGERS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SILENCED_SYSTEM_CHECKS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SILENCED_SYSTEM_CHECKS</span></code></a></li>
</ul>
</div>
<div class="section" id="s-file-uploads">
<span id="s-file-upload-settings"></span><span id="file-uploads"></span><span id="file-upload-settings"></span><h3>文件上传<a class="headerlink" href="#file-uploads" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-DEFAULT_FILE_STORAGE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_FILE_STORAGE</span></code></a></li>
<li><a class="reference internal" href="#std:setting-FILE_UPLOAD_HANDLERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FILE_UPLOAD_HANDLERS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-FILE_UPLOAD_MAX_MEMORY_SIZE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FILE_UPLOAD_MAX_MEMORY_SIZE</span></code></a></li>
<li><a class="reference internal" href="#std:setting-FILE_UPLOAD_PERMISSIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FILE_UPLOAD_PERMISSIONS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-FILE_UPLOAD_TEMP_DIR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FILE_UPLOAD_TEMP_DIR</span></code></a></li>
<li><a class="reference internal" href="#std:setting-MEDIA_ROOT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MEDIA_ROOT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-MEDIA_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MEDIA_URL</span></code></a></li>
</ul>
</div>
<div class="section" id="s-forms">
<span id="forms"></span><h3>表单<a class="headerlink" href="#forms" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-FORM_RENDERER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FORM_RENDERER</span></code></a></li>
</ul>
</div>
<div class="section" id="s-globalization-i18n-l10n">
<span id="globalization-i18n-l10n"></span><h3>国际化（<code class="docutils literal notranslate"><span class="pre">i18n</span></code> ／ <code class="docutils literal notranslate"><span class="pre">l10n</span></code>）<a class="headerlink" href="#globalization-i18n-l10n" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DATE_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_INPUT_FORMATS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DATETIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATETIME_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DATETIME_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATETIME_INPUT_FORMATS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DECIMAL_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DECIMAL_SEPARATOR</span></code></a></li>
<li><a class="reference internal" href="#std:setting-FIRST_DAY_OF_WEEK"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FIRST_DAY_OF_WEEK</span></code></a></li>
<li><a class="reference internal" href="#std:setting-FORMAT_MODULE_PATH"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FORMAT_MODULE_PATH</span></code></a></li>
<li><a class="reference internal" href="#std:setting-LANGUAGE_CODE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_CODE</span></code></a></li>
<li><a class="reference internal" href="#std:setting-LANGUAGE_COOKIE_AGE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_AGE</span></code></a></li>
<li><a class="reference internal" href="#std:setting-LANGUAGE_COOKIE_DOMAIN"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_DOMAIN</span></code></a></li>
<li><a class="reference internal" href="#std:setting-LANGUAGE_COOKIE_HTTPONLY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_HTTPONLY</span></code></a></li>
<li><a class="reference internal" href="#std:setting-LANGUAGE_COOKIE_NAME"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_NAME</span></code></a></li>
<li><a class="reference internal" href="#std:setting-LANGUAGE_COOKIE_PATH"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_PATH</span></code></a></li>
<li><a class="reference internal" href="#std:setting-LANGUAGE_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_SAMESITE</span></code></a></li>
<li><a class="reference internal" href="#std:setting-LANGUAGE_COOKIE_SECURE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_SECURE</span></code></a></li>
<li><a class="reference internal" href="#std:setting-LANGUAGES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGES</span></code></a></li>
<li><a class="reference internal" href="#std:setting-LANGUAGES_BIDI"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGES_BIDI</span></code></a></li>
<li><a class="reference internal" href="#std:setting-LOCALE_PATHS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LOCALE_PATHS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-MONTH_DAY_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MONTH_DAY_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-NUMBER_GROUPING"><code class="xref std std-setting docutils literal notranslate"><span class="pre">NUMBER_GROUPING</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SHORT_DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SHORT_DATE_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SHORT_DATETIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SHORT_DATETIME_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-THOUSAND_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">THOUSAND_SEPARATOR</span></code></a></li>
<li><a class="reference internal" href="#std:setting-TIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-TIME_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_INPUT_FORMATS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-TIME_ZONE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_ZONE</span></code></a></li>
<li><a class="reference internal" href="#std:setting-USE_I18N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_I18N</span></code></a></li>
<li><a class="reference internal" href="#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a></li>
<li><a class="reference internal" href="#std:setting-USE_THOUSAND_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_THOUSAND_SEPARATOR</span></code></a></li>
<li><a class="reference internal" href="#std:setting-USE_TZ"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_TZ</span></code></a></li>
<li><a class="reference internal" href="#std:setting-YEAR_MONTH_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">YEAR_MONTH_FORMAT</span></code></a></li>
</ul>
</div>
<div class="section" id="s-http">
<span id="http"></span><h3>HTTP<a class="headerlink" href="#http" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-DATA_UPLOAD_MAX_MEMORY_SIZE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATA_UPLOAD_MAX_MEMORY_SIZE</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DATA_UPLOAD_MAX_NUMBER_FIELDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATA_UPLOAD_MAX_NUMBER_FIELDS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DEFAULT_CHARSET"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_CHARSET</span></code></a></li>
<li><a class="reference internal" href="#std:setting-DISALLOWED_USER_AGENTS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DISALLOWED_USER_AGENTS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-FORCE_SCRIPT_NAME"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FORCE_SCRIPT_NAME</span></code></a></li>
<li><a class="reference internal" href="#std:setting-INTERNAL_IPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INTERNAL_IPS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-MIDDLEWARE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MIDDLEWARE</span></code></a></li>
<li>安全<ul>
<li><a class="reference internal" href="#std:setting-SECURE_BROWSER_XSS_FILTER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_BROWSER_XSS_FILTER</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SECURE_CONTENT_TYPE_NOSNIFF"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_CONTENT_TYPE_NOSNIFF</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SECURE_HSTS_INCLUDE_SUBDOMAINS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_HSTS_INCLUDE_SUBDOMAINS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SECURE_HSTS_PRELOAD"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_HSTS_PRELOAD</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SECURE_HSTS_SECONDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_HSTS_SECONDS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SECURE_PROXY_SSL_HEADER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_PROXY_SSL_HEADER</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SECURE_REDIRECT_EXEMPT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_REDIRECT_EXEMPT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SECURE_REFERRER_POLICY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_REFERRER_POLICY</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SECURE_SSL_HOST"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_SSL_HOST</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SECURE_SSL_REDIRECT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_SSL_REDIRECT</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#std:setting-SIGNING_BACKEND"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SIGNING_BACKEND</span></code></a></li>
<li><a class="reference internal" href="#std:setting-USE_X_FORWARDED_HOST"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_X_FORWARDED_HOST</span></code></a></li>
<li><a class="reference internal" href="#std:setting-USE_X_FORWARDED_PORT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_X_FORWARDED_PORT</span></code></a></li>
<li><a class="reference internal" href="#std:setting-WSGI_APPLICATION"><code class="xref std std-setting docutils literal notranslate"><span class="pre">WSGI_APPLICATION</span></code></a></li>
</ul>
</div>
<div class="section" id="s-id10">
<span id="id10"></span><h3>日志<a class="headerlink" href="#id10" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-LOGGING"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LOGGING</span></code></a></li>
<li><a class="reference internal" href="#std:setting-LOGGING_CONFIG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LOGGING_CONFIG</span></code></a></li>
</ul>
</div>
<div class="section" id="s-models">
<span id="models"></span><h3>模型<a class="headerlink" href="#models" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-ABSOLUTE_URL_OVERRIDES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">ABSOLUTE_URL_OVERRIDES</span></code></a></li>
<li><a class="reference internal" href="#std:setting-FIXTURE_DIRS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FIXTURE_DIRS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a></li>
</ul>
</div>
<div class="section" id="s-security">
<span id="security"></span><h3>安全<a class="headerlink" href="#security" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li>跨网站请求伪造保护<ul>
<li><a class="reference internal" href="#std:setting-CSRF_COOKIE_DOMAIN"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CSRF_COOKIE_DOMAIN</span></code></a></li>
<li><a class="reference internal" href="#std:setting-CSRF_COOKIE_NAME"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CSRF_COOKIE_NAME</span></code></a></li>
<li><a class="reference internal" href="#std:setting-CSRF_COOKIE_PATH"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CSRF_COOKIE_PATH</span></code></a></li>
<li><a class="reference internal" href="#std:setting-CSRF_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CSRF_COOKIE_SAMESITE</span></code></a></li>
<li><a class="reference internal" href="#std:setting-CSRF_COOKIE_SECURE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CSRF_COOKIE_SECURE</span></code></a></li>
<li><a class="reference internal" href="#std:setting-CSRF_FAILURE_VIEW"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CSRF_FAILURE_VIEW</span></code></a></li>
<li><a class="reference internal" href="#std:setting-CSRF_HEADER_NAME"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CSRF_HEADER_NAME</span></code></a></li>
<li><a class="reference internal" href="#std:setting-CSRF_TRUSTED_ORIGINS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CSRF_TRUSTED_ORIGINS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-CSRF_USE_SESSIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CSRF_USE_SESSIONS</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#std:setting-SECRET_KEY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECRET_KEY</span></code></a></li>
<li><a class="reference internal" href="#std:setting-X_FRAME_OPTIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">X_FRAME_OPTIONS</span></code></a></li>
</ul>
</div>
<div class="section" id="s-serialization">
<span id="serialization"></span><h3>序列化<a class="headerlink" href="#serialization" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-DEFAULT_CHARSET"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_CHARSET</span></code></a></li>
<li><a class="reference internal" href="#std:setting-SERIALIZATION_MODULES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SERIALIZATION_MODULES</span></code></a></li>
</ul>
</div>
<div class="section" id="s-id11">
<span id="id11"></span><h3>模板<a class="headerlink" href="#id11" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-TEMPLATES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TEMPLATES</span></code></a></li>
</ul>
</div>
<div class="section" id="s-testing">
<span id="testing"></span><h3>测试中<a class="headerlink" href="#testing" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li>数据库： <a class="reference internal" href="#std:setting-DATABASE-TEST"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TEST</span></code></a></li>
<li><a class="reference internal" href="#std:setting-TEST_NON_SERIALIZED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TEST_NON_SERIALIZED_APPS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-TEST_RUNNER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TEST_RUNNER</span></code></a></li>
</ul>
</div>
<div class="section" id="s-urls">
<span id="urls"></span><h3>URL<a class="headerlink" href="#urls" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="#std:setting-APPEND_SLASH"><code class="xref std std-setting docutils literal notranslate"><span class="pre">APPEND_SLASH</span></code></a></li>
<li><a class="reference internal" href="#std:setting-PREPEND_WWW"><code class="xref std std-setting docutils literal notranslate"><span class="pre">PREPEND_WWW</span></code></a></li>
<li><a class="reference internal" href="#std:setting-ROOT_URLCONF"><code class="xref std std-setting docutils literal notranslate"><span class="pre">ROOT_URLCONF</span></code></a></li>
</ul>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">配置</a><ul>
<li><a class="reference internal" href="#core-settings">核心配置</a><ul>
<li><a class="reference internal" href="#absolute-url-overrides"><code class="docutils literal notranslate"><span class="pre">ABSOLUTE_URL_OVERRIDES</span></code></a></li>
<li><a class="reference internal" href="#admins"><code class="docutils literal notranslate"><span class="pre">ADMINS</span></code></a></li>
<li><a class="reference internal" href="#allowed-hosts"><code class="docutils literal notranslate"><span class="pre">ALLOWED_HOSTS</span></code></a></li>
<li><a class="reference internal" href="#append-slash"><code class="docutils literal notranslate"><span class="pre">APPEND_SLASH</span></code></a></li>
<li><a class="reference internal" href="#caches"><code class="docutils literal notranslate"><span class="pre">CACHES</span></code></a><ul>
<li><a class="reference internal" href="#backend"><code class="docutils literal notranslate"><span class="pre">BACKEND</span></code></a></li>
<li><a class="reference internal" href="#key-function"><code class="docutils literal notranslate"><span class="pre">KEY_FUNCTION</span></code></a></li>
<li><a class="reference internal" href="#key-prefix"><code class="docutils literal notranslate"><span class="pre">KEY_PREFIX</span></code></a></li>
<li><a class="reference internal" href="#location"><code class="docutils literal notranslate"><span class="pre">LOCATION</span></code></a></li>
<li><a class="reference internal" href="#options"><code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code></a></li>
<li><a class="reference internal" href="#timeout"><code class="docutils literal notranslate"><span class="pre">TIMEOUT</span></code></a></li>
<li><a class="reference internal" href="#version"><code class="docutils literal notranslate"><span class="pre">VERSION</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#cache-middleware-alias"><code class="docutils literal notranslate"><span class="pre">CACHE_MIDDLEWARE_ALIAS</span></code></a></li>
<li><a class="reference internal" href="#cache-middleware-key-prefix"><code class="docutils literal notranslate"><span class="pre">CACHE_MIDDLEWARE_KEY_PREFIX</span></code></a></li>
<li><a class="reference internal" href="#cache-middleware-seconds"><code class="docutils literal notranslate"><span class="pre">CACHE_MIDDLEWARE_SECONDS</span></code></a></li>
<li><a class="reference internal" href="#csrf-cookie-age"><code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_AGE</span></code></a></li>
<li><a class="reference internal" href="#csrf-cookie-domain"><code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_DOMAIN</span></code></a></li>
<li><a class="reference internal" href="#csrf-cookie-httponly"><code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_HTTPONLY</span></code></a></li>
<li><a class="reference internal" href="#csrf-cookie-name"><code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_NAME</span></code></a></li>
<li><a class="reference internal" href="#csrf-cookie-path"><code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_PATH</span></code></a></li>
<li><a class="reference internal" href="#csrf-cookie-samesite"><code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_SAMESITE</span></code></a></li>
<li><a class="reference internal" href="#csrf-cookie-secure"><code class="docutils literal notranslate"><span class="pre">CSRF_COOKIE_SECURE</span></code></a></li>
<li><a class="reference internal" href="#csrf-use-sessions"><code class="docutils literal notranslate"><span class="pre">CSRF_USE_SESSIONS</span></code></a></li>
<li><a class="reference internal" href="#csrf-failure-view"><code class="docutils literal notranslate"><span class="pre">CSRF_FAILURE_VIEW</span></code></a></li>
<li><a class="reference internal" href="#csrf-header-name"><code class="docutils literal notranslate"><span class="pre">CSRF_HEADER_NAME</span></code></a></li>
<li><a class="reference internal" href="#csrf-trusted-origins"><code class="docutils literal notranslate"><span class="pre">CSRF_TRUSTED_ORIGINS</span></code></a></li>
<li><a class="reference internal" href="#databases"><code class="docutils literal notranslate"><span class="pre">DATABASES</span></code></a><ul>
<li><a class="reference internal" href="#atomic-requests"><code class="docutils literal notranslate"><span class="pre">ATOMIC_REQUESTS</span></code></a></li>
<li><a class="reference internal" href="#autocommit"><code class="docutils literal notranslate"><span class="pre">AUTOCOMMIT</span></code></a></li>
<li><a class="reference internal" href="#engine"><code class="docutils literal notranslate"><span class="pre">ENGINE</span></code></a></li>
<li><a class="reference internal" href="#host"><code class="docutils literal notranslate"><span class="pre">HOST</span></code></a></li>
<li><a class="reference internal" href="#name"><code class="docutils literal notranslate"><span class="pre">NAME</span></code></a></li>
<li><a class="reference internal" href="#conn-max-age"><code class="docutils literal notranslate"><span class="pre">CONN_MAX_AGE</span></code></a></li>
<li><a class="reference internal" href="#std:setting-OPTIONS"><code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code></a></li>
<li><a class="reference internal" href="#password"><code class="docutils literal notranslate"><span class="pre">PASSWORD</span></code></a></li>
<li><a class="reference internal" href="#port"><code class="docutils literal notranslate"><span class="pre">PORT</span></code></a></li>
<li><a class="reference internal" href="#time-zone"><code class="docutils literal notranslate"><span class="pre">TIME_ZONE</span></code></a></li>
<li><a class="reference internal" href="#disable-server-side-cursors"><code class="docutils literal notranslate"><span class="pre">DISABLE_SERVER_SIDE_CURSORS</span></code></a></li>
<li><a class="reference internal" href="#user"><code class="docutils literal notranslate"><span class="pre">USER</span></code></a></li>
<li><a class="reference internal" href="#test"><code class="docutils literal notranslate"><span class="pre">TEST</span></code></a><ul>
<li><a class="reference internal" href="#charset"><code class="docutils literal notranslate"><span class="pre">CHARSET</span></code></a></li>
<li><a class="reference internal" href="#collation"><code class="docutils literal notranslate"><span class="pre">COLLATION</span></code></a></li>
<li><a class="reference internal" href="#dependencies"><code class="docutils literal notranslate"><span class="pre">DEPENDENCIES</span></code></a></li>
<li><a class="reference internal" href="#migrate"><code class="docutils literal notranslate"><span class="pre">MIGRATE</span></code></a></li>
<li><a class="reference internal" href="#mirror"><code class="docutils literal notranslate"><span class="pre">MIRROR</span></code></a></li>
<li><a class="reference internal" href="#std:setting-TEST_NAME"><code class="docutils literal notranslate"><span class="pre">NAME</span></code></a></li>
<li><a class="reference internal" href="#serialize"><code class="docutils literal notranslate"><span class="pre">SERIALIZE</span></code></a></li>
<li><a class="reference internal" href="#template"><code class="docutils literal notranslate"><span class="pre">TEMPLATE</span></code></a></li>
<li><a class="reference internal" href="#create-db"><code class="docutils literal notranslate"><span class="pre">CREATE_DB</span></code></a></li>
<li><a class="reference internal" href="#create-user"><code class="docutils literal notranslate"><span class="pre">CREATE_USER</span></code></a></li>
<li><a class="reference internal" href="#std:setting-TEST_USER"><code class="docutils literal notranslate"><span class="pre">USER</span></code></a></li>
<li><a class="reference internal" href="#std:setting-TEST_PASSWD"><code class="docutils literal notranslate"><span class="pre">PASSWORD</span></code></a></li>
<li><a class="reference internal" href="#oracle-managed-files"><code class="docutils literal notranslate"><span class="pre">ORACLE_MANAGED_FILES</span></code></a></li>
<li><a class="reference internal" href="#tblspace"><code class="docutils literal notranslate"><span class="pre">TBLSPACE</span></code></a></li>
<li><a class="reference internal" href="#tblspace-tmp"><code class="docutils literal notranslate"><span class="pre">TBLSPACE_TMP</span></code></a></li>
<li><a class="reference internal" href="#datafile"><code class="docutils literal notranslate"><span class="pre">DATAFILE</span></code></a></li>
<li><a class="reference internal" href="#datafile-tmp"><code class="docutils literal notranslate"><span class="pre">DATAFILE_TMP</span></code></a></li>
<li><a class="reference internal" href="#datafile-maxsize"><code class="docutils literal notranslate"><span class="pre">DATAFILE_MAXSIZE</span></code></a></li>
<li><a class="reference internal" href="#datafile-tmp-maxsize"><code class="docutils literal notranslate"><span class="pre">DATAFILE_TMP_MAXSIZE</span></code></a></li>
<li><a class="reference internal" href="#datafile-size"><code class="docutils literal notranslate"><span class="pre">DATAFILE_SIZE</span></code></a></li>
<li><a class="reference internal" href="#datafile-tmp-size"><code class="docutils literal notranslate"><span class="pre">DATAFILE_TMP_SIZE</span></code></a></li>
<li><a class="reference internal" href="#datafile-extsize"><code class="docutils literal notranslate"><span class="pre">DATAFILE_EXTSIZE</span></code></a></li>
<li><a class="reference internal" href="#datafile-tmp-extsize"><code class="docutils literal notranslate"><span class="pre">DATAFILE_TMP_EXTSIZE</span></code></a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#data-upload-max-memory-size"><code class="docutils literal notranslate"><span class="pre">DATA_UPLOAD_MAX_MEMORY_SIZE</span></code></a></li>
<li><a class="reference internal" href="#data-upload-max-number-fields"><code class="docutils literal notranslate"><span class="pre">DATA_UPLOAD_MAX_NUMBER_FIELDS</span></code></a></li>
<li><a class="reference internal" href="#database-routers"><code class="docutils literal notranslate"><span class="pre">DATABASE_ROUTERS</span></code></a></li>
<li><a class="reference internal" href="#date-format"><code class="docutils literal notranslate"><span class="pre">DATE_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#date-input-formats"><code class="docutils literal notranslate"><span class="pre">DATE_INPUT_FORMATS</span></code></a></li>
<li><a class="reference internal" href="#datetime-format"><code class="docutils literal notranslate"><span class="pre">DATETIME_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#datetime-input-formats"><code class="docutils literal notranslate"><span class="pre">DATETIME_INPUT_FORMATS</span></code></a></li>
<li><a class="reference internal" href="#debug"><code class="docutils literal notranslate"><span class="pre">DEBUG</span></code></a></li>
<li><a class="reference internal" href="#debug-propagate-exceptions"><code class="docutils literal notranslate"><span class="pre">DEBUG_PROPAGATE_EXCEPTIONS</span></code></a></li>
<li><a class="reference internal" href="#decimal-separator"><code class="docutils literal notranslate"><span class="pre">DECIMAL_SEPARATOR</span></code></a></li>
<li><a class="reference internal" href="#default-auto-field"><code class="docutils literal notranslate"><span class="pre">DEFAULT_AUTO_FIELD</span></code></a></li>
<li><a class="reference internal" href="#default-charset"><code class="docutils literal notranslate"><span class="pre">DEFAULT_CHARSET</span></code></a></li>
<li><a class="reference internal" href="#default-exception-reporter"><code class="docutils literal notranslate"><span class="pre">DEFAULT_EXCEPTION_REPORTER</span></code></a></li>
<li><a class="reference internal" href="#default-exception-reporter-filter"><code class="docutils literal notranslate"><span class="pre">DEFAULT_EXCEPTION_REPORTER_FILTER</span></code></a></li>
<li><a class="reference internal" href="#default-file-storage"><code class="docutils literal notranslate"><span class="pre">DEFAULT_FILE_STORAGE</span></code></a></li>
<li><a class="reference internal" href="#default-from-email"><code class="docutils literal notranslate"><span class="pre">DEFAULT_FROM_EMAIL</span></code></a></li>
<li><a class="reference internal" href="#default-hashing-algorithm"><code class="docutils literal notranslate"><span class="pre">DEFAULT_HASHING_ALGORITHM</span></code></a></li>
<li><a class="reference internal" href="#default-index-tablespace"><code class="docutils literal notranslate"><span class="pre">DEFAULT_INDEX_TABLESPACE</span></code></a></li>
<li><a class="reference internal" href="#default-tablespace"><code class="docutils literal notranslate"><span class="pre">DEFAULT_TABLESPACE</span></code></a></li>
<li><a class="reference internal" href="#disallowed-user-agents"><code class="docutils literal notranslate"><span class="pre">DISALLOWED_USER_AGENTS</span></code></a></li>
<li><a class="reference internal" href="#email-backend"><code class="docutils literal notranslate"><span class="pre">EMAIL_BACKEND</span></code></a></li>
<li><a class="reference internal" href="#email-file-path"><code class="docutils literal notranslate"><span class="pre">EMAIL_FILE_PATH</span></code></a></li>
<li><a class="reference internal" href="#email-host"><code class="docutils literal notranslate"><span class="pre">EMAIL_HOST</span></code></a></li>
<li><a class="reference internal" href="#email-host-password"><code class="docutils literal notranslate"><span class="pre">EMAIL_HOST_PASSWORD</span></code></a></li>
<li><a class="reference internal" href="#email-host-user"><code class="docutils literal notranslate"><span class="pre">EMAIL_HOST_USER</span></code></a></li>
<li><a class="reference internal" href="#email-port"><code class="docutils literal notranslate"><span class="pre">EMAIL_PORT</span></code></a></li>
<li><a class="reference internal" href="#email-subject-prefix"><code class="docutils literal notranslate"><span class="pre">EMAIL_SUBJECT_PREFIX</span></code></a></li>
<li><a class="reference internal" href="#email-use-localtime"><code class="docutils literal notranslate"><span class="pre">EMAIL_USE_LOCALTIME</span></code></a></li>
<li><a class="reference internal" href="#email-use-tls"><code class="docutils literal notranslate"><span class="pre">EMAIL_USE_TLS</span></code></a></li>
<li><a class="reference internal" href="#email-use-ssl"><code class="docutils literal notranslate"><span class="pre">EMAIL_USE_SSL</span></code></a></li>
<li><a class="reference internal" href="#email-ssl-certfile"><code class="docutils literal notranslate"><span class="pre">EMAIL_SSL_CERTFILE</span></code></a></li>
<li><a class="reference internal" href="#email-ssl-keyfile"><code class="docutils literal notranslate"><span class="pre">EMAIL_SSL_KEYFILE</span></code></a></li>
<li><a class="reference internal" href="#email-timeout"><code class="docutils literal notranslate"><span class="pre">EMAIL_TIMEOUT</span></code></a></li>
<li><a class="reference internal" href="#file-upload-handlers"><code class="docutils literal notranslate"><span class="pre">FILE_UPLOAD_HANDLERS</span></code></a></li>
<li><a class="reference internal" href="#file-upload-max-memory-size"><code class="docutils literal notranslate"><span class="pre">FILE_UPLOAD_MAX_MEMORY_SIZE</span></code></a></li>
<li><a class="reference internal" href="#file-upload-directory-permissions"><code class="docutils literal notranslate"><span class="pre">FILE_UPLOAD_DIRECTORY_PERMISSIONS</span></code></a></li>
<li><a class="reference internal" href="#file-upload-permissions"><code class="docutils literal notranslate"><span class="pre">FILE_UPLOAD_PERMISSIONS</span></code></a></li>
<li><a class="reference internal" href="#file-upload-temp-dir"><code class="docutils literal notranslate"><span class="pre">FILE_UPLOAD_TEMP_DIR</span></code></a></li>
<li><a class="reference internal" href="#first-day-of-week"><code class="docutils literal notranslate"><span class="pre">FIRST_DAY_OF_WEEK</span></code></a></li>
<li><a class="reference internal" href="#fixture-dirs"><code class="docutils literal notranslate"><span class="pre">FIXTURE_DIRS</span></code></a></li>
<li><a class="reference internal" href="#force-script-name"><code class="docutils literal notranslate"><span class="pre">FORCE_SCRIPT_NAME</span></code></a></li>
<li><a class="reference internal" href="#form-renderer"><code class="docutils literal notranslate"><span class="pre">FORM_RENDERER</span></code></a></li>
<li><a class="reference internal" href="#format-module-path"><code class="docutils literal notranslate"><span class="pre">FORMAT_MODULE_PATH</span></code></a></li>
<li><a class="reference internal" href="#ignorable-404-urls"><code class="docutils literal notranslate"><span class="pre">IGNORABLE_404_URLS</span></code></a></li>
<li><a class="reference internal" href="#installed-apps"><code class="docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a></li>
<li><a class="reference internal" href="#internal-ips"><code class="docutils literal notranslate"><span class="pre">INTERNAL_IPS</span></code></a></li>
<li><a class="reference internal" href="#language-code"><code class="docutils literal notranslate"><span class="pre">LANGUAGE_CODE</span></code></a></li>
<li><a class="reference internal" href="#language-cookie-age"><code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_AGE</span></code></a></li>
<li><a class="reference internal" href="#language-cookie-domain"><code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_DOMAIN</span></code></a></li>
<li><a class="reference internal" href="#language-cookie-httponly"><code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_HTTPONLY</span></code></a></li>
<li><a class="reference internal" href="#language-cookie-name"><code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_NAME</span></code></a></li>
<li><a class="reference internal" href="#language-cookie-path"><code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_PATH</span></code></a></li>
<li><a class="reference internal" href="#language-cookie-samesite"><code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_SAMESITE</span></code></a></li>
<li><a class="reference internal" href="#language-cookie-secure"><code class="docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_SECURE</span></code></a></li>
<li><a class="reference internal" href="#languages"><code class="docutils literal notranslate"><span class="pre">LANGUAGES</span></code></a></li>
<li><a class="reference internal" href="#languages-bidi"><code class="docutils literal notranslate"><span class="pre">LANGUAGES_BIDI</span></code></a></li>
<li><a class="reference internal" href="#locale-paths"><code class="docutils literal notranslate"><span class="pre">LOCALE_PATHS</span></code></a></li>
<li><a class="reference internal" href="#logging"><code class="docutils literal notranslate"><span class="pre">LOGGING</span></code></a></li>
<li><a class="reference internal" href="#logging-config"><code class="docutils literal notranslate"><span class="pre">LOGGING_CONFIG</span></code></a></li>
<li><a class="reference internal" href="#managers"><code class="docutils literal notranslate"><span class="pre">MANAGERS</span></code></a></li>
<li><a class="reference internal" href="#media-root"><code class="docutils literal notranslate"><span class="pre">MEDIA_ROOT</span></code></a></li>
<li><a class="reference internal" href="#media-url"><code class="docutils literal notranslate"><span class="pre">MEDIA_URL</span></code></a></li>
<li><a class="reference internal" href="#middleware"><code class="docutils literal notranslate"><span class="pre">MIDDLEWARE</span></code></a></li>
<li><a class="reference internal" href="#migration-modules"><code class="docutils literal notranslate"><span class="pre">MIGRATION_MODULES</span></code></a></li>
<li><a class="reference internal" href="#month-day-format"><code class="docutils literal notranslate"><span class="pre">MONTH_DAY_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#number-grouping"><code class="docutils literal notranslate"><span class="pre">NUMBER_GROUPING</span></code></a></li>
<li><a class="reference internal" href="#prepend-www"><code class="docutils literal notranslate"><span class="pre">PREPEND_WWW</span></code></a></li>
<li><a class="reference internal" href="#root-urlconf"><code class="docutils literal notranslate"><span class="pre">ROOT_URLCONF</span></code></a></li>
<li><a class="reference internal" href="#secret-key"><code class="docutils literal notranslate"><span class="pre">SECRET_KEY</span></code></a></li>
<li><a class="reference internal" href="#secure-browser-xss-filter"><code class="docutils literal notranslate"><span class="pre">SECURE_BROWSER_XSS_FILTER</span></code></a></li>
<li><a class="reference internal" href="#secure-content-type-nosniff"><code class="docutils literal notranslate"><span class="pre">SECURE_CONTENT_TYPE_NOSNIFF</span></code></a></li>
<li><a class="reference internal" href="#secure-hsts-include-subdomains"><code class="docutils literal notranslate"><span class="pre">SECURE_HSTS_INCLUDE_SUBDOMAINS</span></code></a></li>
<li><a class="reference internal" href="#secure-hsts-preload"><code class="docutils literal notranslate"><span class="pre">SECURE_HSTS_PRELOAD</span></code></a></li>
<li><a class="reference internal" href="#secure-hsts-seconds"><code class="docutils literal notranslate"><span class="pre">SECURE_HSTS_SECONDS</span></code></a></li>
<li><a class="reference internal" href="#secure-proxy-ssl-header"><code class="docutils literal notranslate"><span class="pre">SECURE_PROXY_SSL_HEADER</span></code></a></li>
<li><a class="reference internal" href="#secure-redirect-exempt"><code class="docutils literal notranslate"><span class="pre">SECURE_REDIRECT_EXEMPT</span></code></a></li>
<li><a class="reference internal" href="#secure-referrer-policy"><code class="docutils literal notranslate"><span class="pre">SECURE_REFERRER_POLICY</span></code></a></li>
<li><a class="reference internal" href="#secure-ssl-host"><code class="docutils literal notranslate"><span class="pre">SECURE_SSL_HOST</span></code></a></li>
<li><a class="reference internal" href="#secure-ssl-redirect"><code class="docutils literal notranslate"><span class="pre">SECURE_SSL_REDIRECT</span></code></a></li>
<li><a class="reference internal" href="#serialization-modules"><code class="docutils literal notranslate"><span class="pre">SERIALIZATION_MODULES</span></code></a></li>
<li><a class="reference internal" href="#server-email"><code class="docutils literal notranslate"><span class="pre">SERVER_EMAIL</span></code></a></li>
<li><a class="reference internal" href="#short-date-format"><code class="docutils literal notranslate"><span class="pre">SHORT_DATE_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#short-datetime-format"><code class="docutils literal notranslate"><span class="pre">SHORT_DATETIME_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#signing-backend"><code class="docutils literal notranslate"><span class="pre">SIGNING_BACKEND</span></code></a></li>
<li><a class="reference internal" href="#silenced-system-checks"><code class="docutils literal notranslate"><span class="pre">SILENCED_SYSTEM_CHECKS</span></code></a></li>
<li><a class="reference internal" href="#templates"><code class="docutils literal notranslate"><span class="pre">TEMPLATES</span></code></a><ul>
<li><a class="reference internal" href="#std:setting-TEMPLATES-BACKEND"><code class="docutils literal notranslate"><span class="pre">BACKEND</span></code></a></li>
<li><a class="reference internal" href="#std:setting-TEMPLATES-NAME"><code class="docutils literal notranslate"><span class="pre">NAME</span></code></a></li>
<li><a class="reference internal" href="#dirs"><code class="docutils literal notranslate"><span class="pre">DIRS</span></code></a></li>
<li><a class="reference internal" href="#app-dirs"><code class="docutils literal notranslate"><span class="pre">APP_DIRS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-TEMPLATES-OPTIONS"><code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#test-runner"><code class="docutils literal notranslate"><span class="pre">TEST_RUNNER</span></code></a></li>
<li><a class="reference internal" href="#test-non-serialized-apps"><code class="docutils literal notranslate"><span class="pre">TEST_NON_SERIALIZED_APPS</span></code></a></li>
<li><a class="reference internal" href="#thousand-separator"><code class="docutils literal notranslate"><span class="pre">THOUSAND_SEPARATOR</span></code></a></li>
<li><a class="reference internal" href="#time-format"><code class="docutils literal notranslate"><span class="pre">TIME_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#time-input-formats"><code class="docutils literal notranslate"><span class="pre">TIME_INPUT_FORMATS</span></code></a></li>
<li><a class="reference internal" href="#std:setting-TIME_ZONE"><code class="docutils literal notranslate"><span class="pre">TIME_ZONE</span></code></a></li>
<li><a class="reference internal" href="#use-i18n"><code class="docutils literal notranslate"><span class="pre">USE_I18N</span></code></a></li>
<li><a class="reference internal" href="#use-l10n"><code class="docutils literal notranslate"><span class="pre">USE_L10N</span></code></a></li>
<li><a class="reference internal" href="#use-thousand-separator"><code class="docutils literal notranslate"><span class="pre">USE_THOUSAND_SEPARATOR</span></code></a></li>
<li><a class="reference internal" href="#use-tz"><code class="docutils literal notranslate"><span class="pre">USE_TZ</span></code></a></li>
<li><a class="reference internal" href="#use-x-forwarded-host"><code class="docutils literal notranslate"><span class="pre">USE_X_FORWARDED_HOST</span></code></a></li>
<li><a class="reference internal" href="#use-x-forwarded-port"><code class="docutils literal notranslate"><span class="pre">USE_X_FORWARDED_PORT</span></code></a></li>
<li><a class="reference internal" href="#wsgi-application"><code class="docutils literal notranslate"><span class="pre">WSGI_APPLICATION</span></code></a></li>
<li><a class="reference internal" href="#year-month-format"><code class="docutils literal notranslate"><span class="pre">YEAR_MONTH_FORMAT</span></code></a></li>
<li><a class="reference internal" href="#x-frame-options"><code class="docutils literal notranslate"><span class="pre">X_FRAME_OPTIONS</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#auth">认证</a><ul>
<li><a class="reference internal" href="#authentication-backends"><code class="docutils literal notranslate"><span class="pre">AUTHENTICATION_BACKENDS</span></code></a></li>
<li><a class="reference internal" href="#auth-user-model"><code class="docutils literal notranslate"><span class="pre">AUTH_USER_MODEL</span></code></a></li>
<li><a class="reference internal" href="#login-redirect-url"><code class="docutils literal notranslate"><span class="pre">LOGIN_REDIRECT_URL</span></code></a></li>
<li><a class="reference internal" href="#login-url"><code class="docutils literal notranslate"><span class="pre">LOGIN_URL</span></code></a></li>
<li><a class="reference internal" href="#logout-redirect-url"><code class="docutils literal notranslate"><span class="pre">LOGOUT_REDIRECT_URL</span></code></a></li>
<li><a class="reference internal" href="#password-reset-timeout"><code class="docutils literal notranslate"><span class="pre">PASSWORD_RESET_TIMEOUT</span></code></a></li>
<li><a class="reference internal" href="#password-reset-timeout-days"><code class="docutils literal notranslate"><span class="pre">PASSWORD_RESET_TIMEOUT_DAYS</span></code></a></li>
<li><a class="reference internal" href="#password-hashers"><code class="docutils literal notranslate"><span class="pre">PASSWORD_HASHERS</span></code></a></li>
<li><a class="reference internal" href="#auth-password-validators"><code class="docutils literal notranslate"><span class="pre">AUTH_PASSWORD_VALIDATORS</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#messages">消息</a><ul>
<li><a class="reference internal" href="#message-level"><code class="docutils literal notranslate"><span class="pre">MESSAGE_LEVEL</span></code></a></li>
<li><a class="reference internal" href="#message-storage"><code class="docutils literal notranslate"><span class="pre">MESSAGE_STORAGE</span></code></a></li>
<li><a class="reference internal" href="#message-tags"><code class="docutils literal notranslate"><span class="pre">MESSAGE_TAGS</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#sessions">会话</a><ul>
<li><a class="reference internal" href="#session-cache-alias"><code class="docutils literal notranslate"><span class="pre">SESSION_CACHE_ALIAS</span></code></a></li>
<li><a class="reference internal" href="#session-cookie-age"><code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_AGE</span></code></a></li>
<li><a class="reference internal" href="#session-cookie-domain"><code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_DOMAIN</span></code></a></li>
<li><a class="reference internal" href="#session-cookie-httponly"><code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_HTTPONLY</span></code></a></li>
<li><a class="reference internal" href="#session-cookie-name"><code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_NAME</span></code></a></li>
<li><a class="reference internal" href="#session-cookie-path"><code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_PATH</span></code></a></li>
<li><a class="reference internal" href="#session-cookie-samesite"><code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_SAMESITE</span></code></a></li>
<li><a class="reference internal" href="#session-cookie-secure"><code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_SECURE</span></code></a></li>
<li><a class="reference internal" href="#session-engine"><code class="docutils literal notranslate"><span class="pre">SESSION_ENGINE</span></code></a></li>
<li><a class="reference internal" href="#session-expire-at-browser-close"><code class="docutils literal notranslate"><span class="pre">SESSION_EXPIRE_AT_BROWSER_CLOSE</span></code></a></li>
<li><a class="reference internal" href="#session-file-path"><code class="docutils literal notranslate"><span class="pre">SESSION_FILE_PATH</span></code></a></li>
<li><a class="reference internal" href="#session-save-every-request"><code class="docutils literal notranslate"><span class="pre">SESSION_SAVE_EVERY_REQUEST</span></code></a></li>
<li><a class="reference internal" href="#session-serializer"><code class="docutils literal notranslate"><span class="pre">SESSION_SERIALIZER</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#sites">站点</a><ul>
<li><a class="reference internal" href="#site-id"><code class="docutils literal notranslate"><span class="pre">SITE_ID</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#static-files">静态文件</a><ul>
<li><a class="reference internal" href="#static-root"><code class="docutils literal notranslate"><span class="pre">STATIC_ROOT</span></code></a></li>
<li><a class="reference internal" href="#static-url"><code class="docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a></li>
<li><a class="reference internal" href="#staticfiles-dirs"><code class="docutils literal notranslate"><span class="pre">STATICFILES_DIRS</span></code></a><ul>
<li><a class="reference internal" href="#prefixes-optional">前缀（可选）</a></li>
</ul>
</li>
<li><a class="reference internal" href="#staticfiles-storage"><code class="docutils literal notranslate"><span class="pre">STATICFILES_STORAGE</span></code></a></li>
<li><a class="reference internal" href="#staticfiles-finders"><code class="docutils literal notranslate"><span class="pre">STATICFILES_FINDERS</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#core-settings-topical-index">核心配置专题索引</a><ul>
<li><a class="reference internal" href="#cache">缓存</a></li>
<li><a class="reference internal" href="#database">数据库</a></li>
<li><a class="reference internal" href="#debugging">调试</a></li>
<li><a class="reference internal" href="#email">电子邮件</a></li>
<li><a class="reference internal" href="#error-reporting">发送错误</a></li>
<li><a class="reference internal" href="#file-uploads">文件上传</a></li>
<li><a class="reference internal" href="#forms">表单</a></li>
<li><a class="reference internal" href="#globalization-i18n-l10n">国际化（<code class="docutils literal notranslate"><span class="pre">i18n</span></code> ／ <code class="docutils literal notranslate"><span class="pre">l10n</span></code>）</a></li>
<li><a class="reference internal" href="#http">HTTP</a></li>
<li><a class="reference internal" href="#id10">日志</a></li>
<li><a class="reference internal" href="#models">模型</a></li>
<li><a class="reference internal" href="#security">安全</a></li>
<li><a class="reference internal" href="#serialization">序列化</a></li>
<li><a class="reference internal" href="#id11">模板</a></li>
<li><a class="reference internal" href="#testing">测试中</a></li>
<li><a class="reference internal" href="#urls">URL</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="schema-editor.html"
                        title="上一章"><code class="docutils literal notranslate"><span class="pre">SchemaEditor</span></code></a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="signals.html"
                        title="下一章">信号</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/ref/settings.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">12月 07, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="schema-editor.html" title="&lt;code class=&#34;docutils literal notranslate&#34;&gt;&lt;span class=&#34;pre&#34;&gt;SchemaEditor&lt;/span&gt;&lt;/code&gt;">previous</a>
     |
    <a href="index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="signals.html" title="信号">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>